2

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?

chrisvdb
  • 2,080
  • 2
  • 20
  • 28

1 Answers1

11

Apparently one can chain lookup calls using the subexpression syntax

{{lookup (lookup ../countries countrycode) 'name'}}
chrisvdb
  • 2,080
  • 2
  • 20
  • 28
  • 2
    And, if you need to access more than one property, e.g. `name` and `someotherprop`, you can use `{{#with (lookup ../countries countrycode)}} {{name}} {{someotherprop}} {{/with}}` http://stackoverflow.com/a/42520682/1487413 – Martin Burch Feb 28 '17 at 23:55