我有一个 Handlebars 助手,它接受一个数字并返回一个类名。我只想在foobar存在时运行帮助程序,因为它可能不存在。我最初的尝试是:
{{#each content}}
<div class="other_class {{#if foobar}}{{my_helper foobar}}{{/if}}"></div>
{{/each}}
这不起作用,因为 metamorph 会在if助手所在的位置插入脚本标记占位符。我的第二次尝试是:
{{#each content}}
<div class="other_class {{my_helper foobar}}"></div>
{{/each}}
这也不起作用,因为当 foobar 不存在时,字符串"foobar"被传递给my_helper.
我知道这样做{{unbound foobar}}将呈现值而不绑定它,因此没有脚本标记占位符。有没有办法以if不受约束的方式使用?