Articles in this section

Access parent level variables from within a handlebar {{each}} loop

Problem: When using the #each block handlebar helper there is a need to access a parent level variable within the {{each}} loop.

When building handlebar expressions outside of an #each loop, you can easily reference parent level values, but when an #each loop iterates over an object within the record, how do you reference a parent level value?

Solution: Inside each block scope, only the object we are iterating is available by default. In order to access the parent level properties from within each block, you must prefix the variable with "../".

{{../connection.http.unnencrypted.warehouseId}}

When you use the "../" operator within an #each loop, you can reference values in the parent level values. For reference, the structure of model against which the template will be evaluated is this:

{connection: connObj,
 import: importObj,
 data: dataObj}

Note

Other handlebar syntaxes can do the same thing.

For more examples and details of parent contexts, see: http://handlebarsjs.com/guide/expressions.html#changing-the-context

Was this article helpful?
0 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.