Skip to content

Instantly share code, notes, and snippets.

@codeimpossible
Created October 8, 2012 15:44
Show Gist options
  • Save codeimpossible/3853189 to your computer and use it in GitHub Desktop.
Save codeimpossible/3853189 to your computer and use it in GitHub Desktop.
very simple templating system in javascript
var template = function(template, model) {
for(var p in model) {
if( model.hasOwnProperty(p) ) {
var re = new RegExp( "#{" + p + "}", "ig" );
template = template.replace(re, model[p]);
}
}
return template;
};
alert( template("hello #{name}, it's #{time}", { name: "jared", time: "today" }) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment