Created
August 16, 2012 21:57
-
-
Save jmgunn87/3373972 to your computer and use it in GitHub Desktop.
logicless templating
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
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 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no whitespace