Posted By

chupzzz on 12/26/11


Tagged

js template light


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

slashyy77


Simple JS templater


 / Published in: JavaScript
 

URL: http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/

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

  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.