近来想学Ember.js, 相识到Handlebars模板引擎. 比拟Python Mako, Jinja2 跟简朴. 自定义 Block 异常的轻易Handlebars.registerHelper(name, function() { … });
(function($) {
var compiled = {};
$.fn.handlebars = function(template, data) {
if (template instanceof jQuery) {
template = $(template).html();
}
compiled[template] = Handlebars.compile(template);
this.html(compiled[template](data));
};
})(jQuery);