Add root context to data when using in-built #each and #which helpers #525
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes you need to access variables from the root context in any other sub-context. It can be very painful having to always figure out the right path back to the root context when in multiple loops.
For example in my app i have an i18n object bound to the root context, that my i18n helper needs to access. If I can't easily access the root context i need to workaround this by backing up the context like so
This is painful, and not always possible if the above code is in a partial which might be used from different contexts.
This patch simply adds the root context to the data hash in the #each and #which helpers, so you can build helpers which access the root context like so:
It would be even cooler if you could do this in your templates:
But this would require altering the parser AFAIK which would require a bit more work...
Not sure on the etiquette for updating the distro, so I left those unchanged in this commit.