Articles in this section

Access parent-level variables in a Handlebars #each loop

When you build Handlebars expressions outside an #each loop, you can reference parent-level values directly. But inside an #each loop, only the object you're iterating over is available by default, so you can't reach parent-level values the same way. To access a value from a parent context inside the loop, prefix the variable path with ../.

Reference a parent value with../

The ../ operator moves up one level to the parent context. For example, this expression references warehouseId in the connection object from inside an #each loop:

{{../connection.http.unencrypted.warehouseId}}

For deeper nesting, chain the operator: ../../ moves up two levels, and so on.

The template is evaluated against a model with this top-level structure:

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

Reference the top level with @root

You can also use the @root data variable to reference the top-level context from anywhere inside an #each loop, regardless of how deeply it's nested. For more on changing the context, see the Handlebars.js documentation on parent contexts.