Lookup helper in handlebars

2019-05-22 08:10发布

I have a 'countries' object which I pass as part of the Handlebars context:

{
 'hk': {'name': 'Hong Kong', 'someotherprop': 'someothervalue'},
 'us': {'name': 'United States',  'someotherprop': 'yetanothervalue'},
 ...
}

I want to use the lookup Handlebar helper to find from the countrycode 'hk' the name 'Hong Kong'.

I can get the following object

{'name': 'Hong Kong', 'someotherprop': 'someothervalue'}

using the following Handlebars directive

{{lookup ../countries countrycode}}

but how do I now extract the name property from this object?

1条回答
干净又极端
2楼-- · 2019-05-22 08:29

Apparently one can chain lookup calls using the subexpression syntax

{{lookup (lookup ../countries countrycode) 'name'}}
查看更多
登录 后发表回答