Skip to content

Instantly share code, notes, and snippets.

@gnepud
Created April 7, 2012 20:08
Show Gist options
  • Save gnepud/2331772 to your computer and use it in GitHub Desktop.
Save gnepud/2331772 to your computer and use it in GitHub Desktop.
A simple template parser
function simple_template(str, obj) {
return str.replace(/\{\s*(\w+)\s*\}/g, function(_i, _1) {
return obj[_1] != null ? obj[_1] : '';
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment