Unable to access #each helper variables in child scope
I can't find anything in the documentation that says I should be able to use ../@last but I also don't understand why I can't, or why it throws an error.
The documentation states:
Some helpers like #with and #each allow you to dive into nested objects. When you include ../ segments in your path, Handlebars will change back into the parent context.
Template:
{{#each outer}}
{{#each inner}}
outer index: {{{../@index}}}
inner index: {{{@index}}}
{{/each}}
{{/each}}
with data:
{
outer: [{
inner: [{},{},{}]
},{
inner: [{},{},{}]
}]
}
Throws error (using http://tryhandlebarsjs.com):
Error(s): Error: Parse error on line 3: ...outer index: {{{../@index}}}inner inde ----------------------^ Expecting 'ID', got 'DATA'
There is a specific scenario I have where I can't find a way to implement the use case without being able to access the #each helper variables from a child scope:
https://stackoverflow.com/questions/67994959/how-to-avoid-trailing-comma-when-defining-json-array-by-nested-enumeration-of-hi
-Steve
Figured it out: {{{@../index}}}
Not sure if I should delete my issue or leave it so others benefit maybe?
@steveklett If you have time, it would be nice if you could add documentation for this in https://github.com/handlebars-lang/docs.
I am facing an error while trying to run doc repo locally(SSL error).
Refer to the discussion: https://github.com/handlebars-lang/handlebars.js/discussions/1944
@steveklett If you have time, it would be nice if you could add documentation for this in https://github.com/handlebars-lang/docs.
@jaylinski shall I add documentation for it?
@steveklett If you have time, it would be nice if you could add documentation for this in https://github.com/handlebars-lang/docs.
@jaylinski shall I add documentation for it?
@satyajitnayk Yes, that would be nice.