JavaScript

Handlebars - reaching up to a value in the parent context

By Niall Kader1 min read

I had a weird situation where my data looked like this (the object that gets passed into the template function):

{
 isAdmin: true,
 items:[......]
}

In my template I was looping through the items but within that loop I had to reach back up to the parent context to check the isAdmin value, this seems strange but this is how I got it to work.

{{#each items}}
   {{#if ../../isAdmin}}
     html for admins goes here
   {{else}}
     html for non admins goes here
   {{/if}}
{{/each}