最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - handlebars access global variable: if statement - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Jun 17, 2013 at 15:01 ducinducin 26.5k44 gold badges166 silver badges261 bronze badges 1
  • maybe its worth mentioning, I was looking for reference to global variable inside an each loop. this was actually what i was looking for thanks! – elad silver Commented Apr 7, 2015 at 12:48
Add a ment  | 

1 Answer 1

Reset to default 17

Finally, I've found a solution:

{{#if ../mode}}xyz{{/if}}
发布评论

评论列表(0)

  1. 暂无评论