Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access #each helper variables in child scope #1760

Open
steveklett opened this issue Jun 17, 2021 · 5 comments
Open

Unable to access #each helper variables in child scope #1760

steveklett opened this issue Jun 17, 2021 · 5 comments

Comments

@steveklett
Copy link

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

@steveklett
Copy link
Author

Figured it out: {{{@../index}}}
Not sure if I should delete my issue or leave it so others benefit maybe?

@jaylinski
Copy link
Member

@steveklett If you have time, it would be nice if you could add documentation for this in https://github.com/handlebars-lang/docs.

@satyajitnayk
Copy link

satyajitnayk commented Jun 2, 2023

I am facing an error while trying to run doc repo locally(SSL error).
Refer to the discussion: #1944

@satyajitnayk
Copy link

@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?

@jaylinski
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants