是否可以在Spacebars中使用逻辑运算符(没有模板助手)?
例如:
{{#if status == '0'}}
Hello world.
{{/if}}
不幸的是,我收到以下错误:
While processing files with templating (for target web.browser):
client/views/test.html:46: Expected identifier, number, string, boolean, null, or a sub expression enclosed in "(", ")"
... {{#if status == '0'}} ...
^
=> Your application has errors. Waiting for file change.
答案 0 :(得分:6)
Spacebars无法进行比较,但您可以使用原生underscore。在客户注册:
Template.registerHelper('_', function(){
return _;
});
然后像这样使用它:
{{_.isEqual status 0}}
如果状态为0,则返回true
,否则返回false
。