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

Using key / context in helpers #1840

Open
btalb opened this issue Mar 21, 2022 · 1 comment · May be fixed by #1952
Open

Using key / context in helpers #1840

btalb opened this issue Mar 21, 2022 · 1 comment · May be fixed by #1952
Labels
Milestone

Comments

@btalb
Copy link

btalb commented Mar 21, 2022

Consider the following two uses of a custom helper that needs to know information about the evaluation context in which it's been run:

{{#each robots}}
{{helperThatNeedsToKnowWhichRobot this}}
{{/each}}
{{#with robots.husky}}
{{helperThatNeedsToKnowWhichRobot this}}
{{/with}}

In the first case, my helper receives an options object with the following useful data fields:

    data: {                                                                                              
      root: [Object],                                                                                    
      _parent: [Object],                            
      key: 'husky',                                 
      index: 2,                                     
      first: false,                                 
      last: false                                   
    },  

But the second example gives me nothing to work with:

    data: { root: [Object] }

How can I implement the described helper which will also work in a with evaluation context?

@jaylinski
Copy link
Member

jaylinski commented May 25, 2022

If I understand you correctly, you want to access the robots-object inside the robots.husky-block as a _parent-object when using the with-helper?

I guess that's a reasonable feature request. Should be doable by simply copying these lines to the with.js-helper:

Would be nice if you could open a PR with a fix and a test-case. I'm not sure if this would be a breaking change, since some helpers may rely on the _parent-object not to be present. 🤔

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

Successfully merging a pull request may close this issue.

2 participants