Last active
May 5, 2017 21:17
-
-
Save jfolds/c26450510242dfbcf2d2422acb1c1e40 to your computer and use it in GitHub Desktop.
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
let template = '<h1>My name is {{name}}. This is a {{adjective1}} {{adjective2}} template!</h1>'; | |
let model = { | |
name: 'Jeremy', | |
adjective1: 'super', | |
adjective2: 'awesome' | |
}; | |
function _template(tmpl, data) { | |
for (var property in data) { | |
if (data.hasOwnProperty(property)) { | |
tmpl = tmpl.replace(`{{${property}}}`, data[property]); | |
} | |
} | |
return tmpl; | |
} | |
console.log(_template(template, model)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment