Skip to content

Instantly share code, notes, and snippets.

@jfolds
Last active May 5, 2017 21:17
Show Gist options
  • Save jfolds/c26450510242dfbcf2d2422acb1c1e40 to your computer and use it in GitHub Desktop.
Save jfolds/c26450510242dfbcf2d2422acb1c1e40 to your computer and use it in GitHub Desktop.
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