Skip to content

Instantly share code, notes, and snippets.

@laverboy
Last active December 27, 2015 16:39
Show Gist options
  • Save laverboy/7356594 to your computer and use it in GitHub Desktop.
Save laverboy/7356594 to your computer and use it in GitHub Desktop.
Really simple javascript templating. Input is html string and data object.
function createTemplateFromObject(template, data) {
var t = '';
// For each item in the object, make the necessary replacement
for (key in data) {
console.log(key, data);
reg = new RegExp('{{' + key + '}}', 'ig');
t = (t || template).replace(reg, data[key]);
}
console.log(t);
return t;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment