Handlebars.Net icon indicating copy to clipboard operation
Handlebars.Net copied to clipboard

Getting the @index / @first / @last from a root context

Open breenyoung opened this issue 10 years ago • 4 comments

Maybe I'm gettin the syntax wrong, but anyone know if when you're in a nested each loop you can get at the parent's context of @index/first/last in the parent loop?

{{@each}}

Parent index: {{@index}}

{{#each}}

    How to get at parent @index?
    {{../@index}} ?
    {{@root.index}} ?

{{/each}}

{{/each}}

breenyoung avatar Mar 23 '16 13:03 breenyoung

Need to figure out why, {{../../@index}} will get you the current parent index. That isn't correct or intuitive, but that's how it seems to work right now.

rexm avatar Mar 23 '16 13:03 rexm

How does handlebarsjs work in this situation?

rexm avatar Mar 25 '16 23:03 rexm

From here

Nested each blocks may access the interation variables via depth based paths. To access the parent index, for example, {{@../index}} can be used.

imsedim avatar May 11 '16 13:05 imsedim

Isn't this fixed with #174?

304NotModified avatar Aug 02 '19 21:08 304NotModified