目前没有办法直接编译 Handlebars 字符串。Meteor 包装了 Handlebars,只为 ast(抽象语法树)提供了编译方法,而不是直接提供字符串。但是,您可以提供自己的不是 Handlebars 函数的函数。它不是公共 API,但您可以通过这种方式创建 Meteor 模板(暂时,除非 API 更改):
< 0.6.5:
var tmpl = Meteor._def_template("templateName", function () {
return "some html string";
});
0.6.5
var tmpl = Meteor.__define__("templateName", function () {
return "some html string";
});
因此,这将在命名空间中创建一个模板,Template
并为您提供模板的所有良好 Meteor 功能(例如反应性、事件、地标等)。
您还可以通过观看 Spark(Meteor 的底层渲染引擎)上的这一系列截屏视频来了解更多关于幕后发生的事情。
http://www.eventedmind.com/posts/meteor-rendering-template-functions
http://www.eventedmind.com/posts/meteor-introduction-to-rendering