Last active
December 27, 2015 10:19
-
-
Save jtenner/7310280 to your computer and use it in GitHub Desktop.
String prototype Template function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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