Search code examples
handlebars.js

Lookup helper in handlebars


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?


Solution

  • Apparently one can chain lookup calls using the subexpression syntax

    {{lookup (lookup ../countries countrycode) 'name'}}