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

docs/v7/helper-refs/ #5

Open
utterances-bot opened this issue Jan 10, 2020 · 2 comments
Open

docs/v7/helper-refs/ #5

utterances-bot opened this issue Jan 10, 2020 · 2 comments

Comments

@utterances-bot
Copy link

Helper References

A helper reference is a reference that points to data created by a helper. For example, when looping through an object using the foreach helper, you can access the value of the current child key by using {{@index}}

https://squirrelly.js.org/docs/v7/helper-refs/

Copy link

tafandi commented Jan 10, 2020

Hi, could you please give some examples about the IDs, especially the benefit/where it will be useful?

Thanks

@nebrelbug
Copy link
Collaborator

@tafandi great question! Basically, ID's are really helpful in easily accessing references inside scoped helpers. So if you have a really large nest of loops and you want to access the key of the topmost loop from inside the innermost loop, instead of doing this:

{{foreach(obj1)}}
{{foreach(obj2)}}
{{foreach(obj3)}}
{{foreach(obj4)}}
{{@../../../key}}
{{/foreach}}
{{/foreach}}
{{/foreach}}
{{/foreach}}

You can do this:

{{foreach(obj1) loop1}}
{{foreach(obj2)}}
{{foreach(obj3)}}
{{foreach(obj4)}}
{{@loop1:key}}
{{/foreach}}
{{/foreach}}
{{/foreach}}
{{/foreach}}

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

No branches or pull requests

3 participants