Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars Failover Content With Lookup Helper

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

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?

I was hoping to do something like:

{{#> (lookup . 'type') }}
Failover content
{{/(lookup . 'type')}}
like image 763
ametsfan18 Avatar asked Sep 11 '25 02:09

ametsfan18


1 Answers

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!

like image 77
ametsfan18 Avatar answered Sep 12 '25 16:09

ametsfan18