Logic in Handlebars if/else statement?

后端 未结 3 855
清歌不尽
清歌不尽 2020-12-22 12:03

Forgive me for the stupid question, I know you\'re not supposed to put logic in handlebars expressions, but I\'m new to this and I\'m not sure how to get around it.

3条回答
  •  失恋的感觉
    2020-12-22 12:44

    You are right that the common guidance is to limit the use of logic in your views. Sometimes you will need it, but in this example we can go without.

    Handlebars is referencing values that are passed into the template function as its context. You can use some branching logic to assign a variable to the value you need, then in the template reference that value directly.

    The details will vary depending on how you are using Handlebars, but here's an example:

    
    
    

提交回复
热议问题