问题描述
<$ p $
我有一个hbs模板,我有一个对象数组和一个布尔切换变量(切换模板行为) p> {
objs:list,
mode:true
}
当循环内部 objs
时,我无法访问模式
(上下文被改变)。我想要的是使用上面的变量来创建一个if语句。我发现我可以写一个自定义帮手。但是没有其他方式可以访问变量吗?我还发现,在循环内部,变量可以通过 {{../ mode}}
来访问 - 但仍然不知道如何访问它。
解决方案
{{#if ../mode}}xyz{{/if}}
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.
Finally, I've found a solution:
{{#if ../mode}}xyz{{/if}}
这篇关于句柄访问全局变量:if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!