Skip to content

Instantly share code, notes, and snippets.

@jtenner
Last active December 27, 2015 10:19
Show Gist options
  • Save jtenner/7310280 to your computer and use it in GitHub Desktop.
Save jtenner/7310280 to your computer and use it in GitHub Desktop.
String prototype Template function
String.prototype.template = function(templateObject){
return this.replace(/\{\{([a-zA-Z\_0-9\.]*?)\}\}/g, function(match){
var temp = templateObject;
match.slice(2,-2).split('.').forEach(function(item){
temp = temp[item];
});
return temp;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment