handlebars access global variable: if statement

2019-02-27 02:58发布

问题:

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}}