/ Published in: JavaScript
*String template (String template, Object data)*
Usage:
template('Hello <b>${name}!</b> (not ${name}?)', { name: 'Gandalf' })
Result: Hello <b>Gandalf!</b> (not Gandalf?)
Usage:
template('Hello <b>${name}!</b> (not ${name}?)', { name: 'Gandalf' })
Result: Hello <b>Gandalf!</b> (not Gandalf?)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; }