Created
June 28, 2013 16:12
-
-
Save kriansa/5885902 to your computer and use it in GitHub Desktop.
Simple Javascript template parser
This file contains 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
/** | |
* Replaces any ${variables} in the template string by the data object | |
*/ | |
var parseTemplate = function(template, data) { | |
return template.replace(/\$\{([\w\d]+)\}/g, function(token, variable){ | |
return data[variable]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment