Skip to content

Instantly share code, notes, and snippets.

@madrobby
Created May 8, 2011 19:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save madrobby/961608 to your computer and use it in GitHub Desktop.
Save madrobby/961608 to your computer and use it in GitHub Desktop.
function t(s,d,p){for(p in d)s=s.replace(new RegExp('{'+p+'}','g'),d[p]);return s;}
/*
String templating engine:
t("Hello {name}!, It is {date}!", { name: "Thomas", date: function(){ return new Date }});
// = "Hello Thomas!, It is Sun May 08 2011 15:15:33 GMT-0400 (EDT)!"
*/
@amackworth
Copy link

Awesomeness!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment