使用查找助手的车把故障转移内容 [英] Handlebars Failover Content With Lookup Helper

查看:96
本文介绍了使用查找助手的车把故障转移内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找通过Lookup帮助器局部渲染车把的方法.这不是问题,我可以使用以下代码做到这一点:

I am looking to render a handlebars partial via the Lookup helper. This isn't a problem, I can do that with this code:

{{> (lookup . 'type') }}

但是,如果变量type没有呈现我的partials目录中的值,则抛出500错误.车把通过故障转移内容对此提供支持.如:

However, if the variable type doesn't render a value that is in my partials directory, then a 500 error throws. Handlebars supports this with failover content. Such as:

{{#> myPartial }}
  Failover content
{{/myPartial}}

我的问题是,我可以将查找与故障转移结合起来吗?

My question is, can I combine the lookup with the failover?

我希望做类似的事情:

{{#> (lookup . 'type') }}
Failover content
{{/(lookup . 'type')}}

推荐答案

谢谢@ 76484,但我想我找到了我想要的东西:

Thank you @76484 but I think I found what I was looking for:

{{#> (lookup . 'type') }}<!-- Return Nothing if Undefined -->{{/undefined}}

这避免了需要帮助者,并且完全满足了我的需求!

This avoids the need for a helper, and does exactly what I was looking for!

这篇关于使用查找助手的车把故障转移内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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