Skip to content

Instantly share code, notes, and snippets.

@jmgunn87
Created August 16, 2012 21:57
Show Gist options
  • Save jmgunn87/3373972 to your computer and use it in GitHub Desktop.
Save jmgunn87/3373972 to your computer and use it in GitHub Desktop.
logicless templating
function renderTemplate (template, args) {
return template.replace (/({{[^{}]*}})/g,
function (match) {
return args [match.substr(2, match.length-4)];
});
}
renderTemplate('<h1>{{name}}:{{total_coins}}</h1>', {
fbid: '3g23403j4999',
name: 'barry',
total_coins: 500
});
@jmgunn87
Copy link
Author

no whitespace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment