Logic in Handlebars if/else statement?

后端 未结 3 858
清歌不尽
清歌不尽 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:58

    Ideally you'd want to create a property on the form object that would give you the info you need, e.g. form.targetIsNew and/or form.targetIsEdit. If you set that beforehand then you can use it in your if/else block.

    So before rendering the handlebars template, set one of those properties:

    form.targetIsNew = form.target == 'new';
    

    You can also use block helpers if things are more complex.

提交回复
热议问题