Is it possible to assign a parameter value within handlebars templates without using helpers?

前端 未结 1 2002
眼角桃花
眼角桃花 2021-02-11 21:17

I am trying to assign values within a template, the idea is to do something like this:

    {{#if author}}
        {{className = \'classA\'}}  <- trying to imp         


        
相关标签:
1条回答
  • 2021-02-11 22:20

    You can do this with a partial.

    partial:

    <div class="{{classname}}">{{var1.author}}</div>
    

    template:

    {{#if author}}
    {{> mypartial var1=. classname="classA"}}
    {{else}}
    {{> mypartial var1=. classname="classB"}}
    {{/if}}
    

    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.

    0 讨论(0)
提交回复
热议问题