Revision: 38142
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 26, 2010 20:48 by emdin
Initial Code
function template (template, data) {
var result = template;
for (var field in data) {
var re = new RegExp( '\\$\\{' + field + '\\}', 'gi' );
result = result.replace(re, data[field]);
}
return result;
}
Initial URL
Initial Description
*String template (String template, Object data)*
Usage:
template('Hello <b>${name}!</b> (not ${name}?)', { name: 'Gandalf' })
Result: Hello <b>Gandalf!</b> (not Gandalf?)
Initial Title
Simplest template engine
Initial Tags
template
Initial Language
JavaScript