Reference a Variable Outside of a Handlebars Each Loop

November 17, 2016

Once within an Handlebars each loop, you can no longer just reference a variable that is outside the loop.  In the example below, the first 'ParentVariable' will render correctly, but the one within the "each" loop won't. 

 

{{ParentVariable}}
{{#each Users}}
     {{ParentVariable}}
{{/each}}

 

To use the variable within the "each" block, you'll need to add a "../" before the variable to reference it:

 

 

{{ParentVariable}}
{{#each Users}}
     {{../ParentVariable}}
{{/each}}