Skip to content

Instantly share code, notes, and snippets.

@usefulthink
Created June 5, 2012 10:48
Show Gist options
  • Save usefulthink/2874360 to your computer and use it in GitHub Desktop.
Save usefulthink/2874360 to your computer and use it in GitHub Desktop.
JS µTemplating
(function(global) {
var tpl = function(template, data) {
var proc = function(data) {
var ret = template;
for (var k in data) {
if (data.hasOwnProperty(k)) {
ret = ret.replace('#{'+k+'}', data[k]);
}
}
return ret;
};
if(data) { return proc(data); }
return proc;
};
global.tpl = tpl;
} (this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment