Skip to content

Instantly share code, notes, and snippets.

@JiLiZART
Created April 26, 2013 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JiLiZART/5464953 to your computer and use it in GitHub Desktop.
Save JiLiZART/5464953 to your computer and use it in GitHub Desktop.
doT.js jQuery wrapper function by Artem Sapegin
$.fn.tmpl = function(tmplId, data) {
var tmpl = doT.template($('#tmpl_' + tmplId).text());
if (!$.isArray(data)) data = [data];
return this.each(function() {
var html = '';
for (var itemIdx = 0; itemIdx < data.length; itemIdx++) {
html += tmpl(data[itemIdx]);
}
$(this).html(html);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment