Handlebars.registerHelper('text', function(isVote,num, options){ if(isVote==num){ return options.fn(this); } else { return options.inverse(this); } });
下边是模版,上边返回的options.fn(this)是内容hello options.inverse(this)是空
参数isVote 是1 num是0 这样可以进行表达式的判断了。但是模版中传递的参数必须是数字。或者是例如
var tpl=$tplContentNews.html(); var template=Handlebars.compile(tpl); var html=template({data:info.data});
这样传递的data。否则其他的数据类行是不行的。我也不知道为什么。网上的资料中都可以传递字符串啊。比如 {{#text 'hello' 'world'}} 可是我写的时候就是不能这样。所以如果是判断字符串与字符串的逻辑关系的话要就在data的那个对象中传递吧
{{#text 1 0}} hello {{/text}}