根据这一blog post,我要注册一个辅助,以便更好地调试车把模板,但不工作:如何在Meteor/handlebars中调试模板?
ReferenceError: Handlebars is not defined
所以,我怎么能在流星/车把{{debug}}
?
根据这一blog post,我要注册一个辅助,以便更好地调试车把模板,但不工作:如何在Meteor/handlebars中调试模板?
ReferenceError: Handlebars is not defined
所以,我怎么能在流星/车把{{debug}}
?
为了完整起见:您还可以使用
Template.registerHelper('helper', helperFunc);
,而不是Handlebars.regsterHelper('h',f);
一个小原因,这是更好的是,那么如果你决定某处您的应用程序将不再需要那么多的重构沿着你想要使用别的东西而不是把手的道路(即Spacebars,流星适应的真实名称),如jade for meteor。
这实在是对accepted answer的评论。期待有一天打50个代表。
请确保您注册助手在客户端(或共享)流星码。
Handlebars.registerHelper('helper', function() {
// Do stuff
});
这应该可以通过您的模板中的{{helper}}
进行调用。
流星0.4.0您注册的处理程序是这样的:
Template.myTemplate.helpers({
helper: function() {
// some code here
console.log(arguments);
}
});
没有必要直接调用把手。
这是辅助函数我在我自己的项目来进行调试:
Template.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);
if (optionalValue) {
console.log("Value");
console.log("====================");
console.log(optionalValue);
}
});
然后你可以把它与{{debug}}
您的模板,它会显示你当前的背景下,更多的http://docs.meteor.com/#/full/template_registerhelper。
流星的api已经发生了变化,现在看来它应该和你说的一样。 – zVictor