If I use underscore.js\'s _.template() from inside a Google Chrome extension I get the following error in the console:
Uncaught Error: Code generation
You can write your own template mini-engine using jQuery's $(' construction.
The clean way:
function myElement(text) {
var d = $('');
d.text(text);
return d;
}
myElement('my text').appendTo(domParent);
The dirty way:
var yourTemplate = '${somevar}';
function instTemplate(tmpl, text) {
return $(tmpl.replace(/\$\{somevar\}/g, text));
}
instTemplate(yourTemplate, 'your text').appendTo(domParent);
E.g. it's pretty quick to rewrite simple jquery.tmpl templates using the dirty method, if you know that the replacement data is not harmful, etc.