如何使用Handlebars三元助手? [英] How to use Handlebars ternary helper?
本文介绍了如何使用Handlebars三元助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按照这个答案,我写了一个像
module.exports.register = function (Handlebars) {
Handlebars.registerHelper('ternary', function(test, yes, no) {
return test ? yes : no;
});
};
我确定帮助程序已被加载并被定义,但无法找出语法用它。我尝试过使用它,比如
I'm certain that the helper is loaded and being defined but can't figure out the syntax to use it. I tried using it like
<div>{{ternary(true, 'yes', 'no')}}</div>
但是给出 assemble 构建错误
but that gives an assemble build error
Warning: Parse error on line 10:
...<div>{{ternary(true, 'yes',
----------^
Expecting 'ID', 'DATA', got 'INVALID' Use --force to continue.
使用这样的助手的正确语法是什么?
What is the proper syntax to use a helper like that?
推荐答案
把手帮手: http://handlebarsjs.com /#helpers 不遵循模板中的JavaScript语法,您可以像这样使用它们:
Handlebars helpers: http://handlebarsjs.com/#helpers don't follow the JavaScript syntax in the templates. You can use them like this:
<div>{{ternary true "yes" "no"}}</div>
这篇关于如何使用Handlebars三元助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文