问题
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