句柄访问全局变量:if语句 [英] handlebars access global variable: if statement

查看:130
本文介绍了句柄访问全局变量:if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



<$ 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语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆