Skip to content

Instantly share code, notes, and snippets.

@kriansa
Created June 28, 2013 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriansa/5885902 to your computer and use it in GitHub Desktop.
Save kriansa/5885902 to your computer and use it in GitHub Desktop.
Simple Javascript template parser
/**
* 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