Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor 1.2 Pass @Index to Child Template

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?

like image 470
reubenb87 Avatar asked Sep 25 '22 16:09

reubenb87


1 Answers

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

like image 125
Keith Nicholas Avatar answered Sep 29 '22 05:09

Keith Nicholas