是否可以在不使用帮助器的情况下在车把模板中分配参数值? [英] Is it possible to assign a parameter value within handlebars templates without using helpers?
本文介绍了是否可以在不使用帮助器的情况下在车把模板中分配参数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在模板中分配值,其想法是执行以下操作:
I am trying to assign values within a template, the idea is to do something like this:
{{#if author}}
{{className = 'classA'}} <- trying to implement this line.
{{else}}
{{className = 'classB'}}
{{/if}}
<div class={{className}}></div>
是否可以在没有registerHelper的情况下这样做?
Is it possible to do so without registerHelper?
推荐答案
您可以使用 partial .
部分:
<div class="{{classname}}">{{var1.author}}</div>
模板:
{{#if author}}
{{> mypartial var1=. classname="classA"}}
{{else}}
{{> mypartial var1=. classname="classB"}}
{{/if}}
在此示例中,我将当前范围传递为var1.我不记得是否范围保持不变,只是将新变量添加到其中,还是必须手动传递范围.
In this example I've passed the current scope as var1. I can't recall if the scope stays the same and the new variable is just added to it or if you have to pass the scope manually.
这篇关于是否可以在不使用帮助器的情况下在车把模板中分配参数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文