Just started using Meteor so I might be missing something basic. In Meteor 1.2 they have the {{@index}}
directive.
In a template if I have:
...
{{#each items}}
{{@index}}
{{> childTemplate}}
{{/each}}
...
<template name="childTemplate">
{{@index}}
</template>
The @index
in the main template will work, but the one in the childTemplate won't. The work around I've done to use it is to call the childTemplate passing in @index
:
{{> childTemplate @index=@index}}
Is this the correct way to do it? Or is there something more meteory?
Yes, that's fine
There's a similar question I answered here :-
How to get the @index of nested #each in meteor
But in this case passing it in is good.
Meteor has "../var"
to get to the parent context, but that is the template context, not the each block, so I don't think there is a more meteory way
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With