Posted By

chupzzz on 12/26/11


js template light

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Simple JS templater

 / Published in: JavaScript


Using: t("Hello {who}!", { who: "JavaScript" }); t("Hello {who}! It's {time} ms since epoch.", { who: "JavaScript", time: });

  1. function t(s,d){
  2. for(var p in d)
  3. s=s.replace(new RegExp('{'+p+'}','g'), d[p]);
  4. return s;
  5. }

Report this snippet  

You need to login to post a comment.