Skip to content

Instantly share code, notes, and snippets.

@simodima
Last active August 29, 2015 14:01
Show Gist options
  • Save simodima/0b139fdc746a88161a49 to your computer and use it in GitHub Desktop.
Save simodima/0b139fdc746a88161a49 to your computer and use it in GitHub Desktop.
superminimal javascript templating
String.prototype.render = function(data){
return this.replace(
/\{([^{}]*)\}/g,
function(match, group){
var value = data[group];
if( typeof value === 'function' ) {
return value.apply(data);
} else if(typeof value === 'number' || typeof value === 'string') {
return value;
}
return match;
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment