如何使用Handlebars三元助手?

如何使用Handlebars三元助手?

问题描述:

this answer,我写了一个帮手像如何使用Handlebars三元助手?

module.exports.register = function (Handlebars) { 
    Handlebars.registerHelper('ternary', function(test, yes, no) { 
     return test ? yes : no; 
    }); 
}; 

我敢肯定,辅助装载和被定义,但不能找出使用它的语法。我试图使用它像

<div>{{ternary(true, 'yes', 'no')}}</div> 

但给出了一个assemble生成错误

Warning: Parse error on line 10: 
...<div>{{ternary(true, 'yes', 
----------^ 
Expecting 'ID', 'DATA', got 'INVALID' Use --force to continue. 

什么是用那样一个辅助的正确语法?

把手助手:http://handlebarsjs.com/#helpers不遵循模板中的JavaScript语法。您可以使用它们像这样:

<div>{{ternary true "yes" "no"}}</div> 

更新2017年7月14日

由于这两个字符串被视为在JavaScript truthy价值,我改变了我的代码如下:

{{input value=email placeholder="Enter Email" class="form-control" 
    disabled=(if isResetting 1 0) 
}} 

============================

原来的答案

如何tryi ng如果使用内嵌{{if}}

{{if user.isAdmin "True" "False" }}