Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created September 18, 2011 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/1225181 to your computer and use it in GitHub Desktop.
Save Integralist/1225181 to your computer and use it in GitHub Desktop.
@madrobby's 140 bytes template engine
function template(string, data, prop) {
for (prop in data) {
string = string.replace(new RegExp('{' + prop + '}', 'g'), data[prop]);
}
return string;
}
/*
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