Handlebar syntax

I know I can reach a specific pagedata value like this
{{@root.pageData.runtimes.items.1.fef_minutes}} while in a #each loop,
but if I want to use the @index or @key instead of the number .1. above, it doesn’t work.
Do I need to use triple brackets or something else I’m missing in the syntax?

Hi Lars,

Can you please include a screenshot of your configuration, your array values, and the syntax you are seeing?

Thanks!
Julia

Hi Lars,

To access the loop’s index, you should be using @root a bit differently than you currently are, you can access the current item with this. Per the documentation, “For both arrays and objects, {{this}} represents the current item in the loop; or, put another way, the value at {{anArray.[@index]}} or {{anObject.[@key]}}.” The Kanarra example uses the following loop to access the name of the current item:

{{#each @root.pageData.selectedGroups}}
    <p>{{this.name}}</p>
  {{/each}}

Thanks!
Julia

I don’t think I explaned good enough. When I use the code below it works fine, but when I try to access a value from the second “runtimes” array using the same index, I get nothing.
image

Handlebar’s built-in lookup helper can be used to dynamically reference a key. It only goes one level deep, so you have to nest them to access deep objects.

{{ lookup (lookup (lookup @root.pageData.runtimes.items @key) 'farr' ) 'minutes' }}

Here’s a helpful thread with usage examples:

If you’d rather not do the nesting, you can use the built-in with helper to shift the context.

{{#with (lookup @root.pageData.runtimes.items @key)}}
  <span>Hello {{ farr.minutes }}</span>
{{/with}}

Here’s a helpful thread on that: