handlebars access global variable: if statement

会有一股神秘感。 提交于 2020-01-11 11:13:33

问题


I've got a hbs template where I've got an array of objects and a boolean toggle variable (toggles the template behavior), let's say:

{
  objs: list,
  mode: true
}

I'm not able to access the mode variable when inside the loop over objs (the context is changed). What I want is to make an if-statement using the upper variable. I found that I can write a custom helper. But is there no other way to access the variable? I also found out, that inside the loop the variable is accessible via {{../mode}} - but still, don't know how to access that.


回答1:


Finally, I've found a solution:

{{#if ../mode}}xyz{{/if}}


来源:https://stackoverflow.com/questions/17150721/handlebars-access-global-variable-if-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!