Reputation:
I am getting dynamic content from database and I want to to view index value like..1,2,3,4,5,6,7
and so on.
I am using {{ @index }}
and {{ index }}
but it is not working for me.
<template name="getDynamic">
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>First Name</td>
<td>last Name</td>
<td>Email</td>
<td>password</td>
<td>Gender</td>
<td>Trems</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
{{#each listalltests}} {{> list }} {{/each}}
</tbody>
</table>
</template>
<template name="list">
<tr>
<td> {{@index}} </td> // not working
<td> {{ username }} </td>
<td> {{ lastname }} </td>
<td> {{ email }} </td>
<td> {{ password }} </td>
<td> {{ gender }} </td>
<td> {{ terms }} </td>
<td>[<a href="#" class="delete-todo">Delete</a>] </td>
<!-- <td>[<a href="#" class="update-todo">Update</a>] </td> -->
</tr>
</template>
Is there a way to access array index in spacebars In meteor?
Upvotes: 1
Views: 66
Reputation: 8423
Your list
template does not know about @index
so you need to pass it to the template.
You need therefore to call it like so
{{ > list index=@index }}
Of course you then need to change your code in the list template to access the item data:
<td>{{index}}</td>
Upvotes: 1