Skip to content

Instantly share code, notes, and snippets.

@amackworth
Forked from madrobby/templating.js
Created May 8, 2011 22:33
Show Gist options
  • Select an option

  • Save amackworth/961760 to your computer and use it in GitHub Desktop.

Select an option

Save amackworth/961760 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)!"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment