Last active
December 27, 2015 16:39
-
-
Save laverboy/7356594 to your computer and use it in GitHub Desktop.
Really simple javascript templating. Input is html string and data object.
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 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