I am trying to use @index in handlebars as follows:
<script id="some-template" type="text/x-handlebars-template">
<form class = "pod" action="#" method="post">
<table>
<thead>
<th>Name</th>
<th>shipment</th>
<th>Button</th>
</thead>
<tbody>
{{#each objects}}
<tr>
<td>{{name}}</td>
<td> <input type="text" id="Shipment" name={{join 'Shipment' name}} /> </td>
<td> <input type="submit" name="actionButton" value = "update" > </td>
{{#if @index == 2 }}
<td>
<a href ="http://www.datatables.net/examples/api/select_single_row.html{{name}}"> {{name}} </a>
</td>
<td> </td>
{{/if}}
{{/each}}
</tbody>
</table>
</form>
</script>
But my if condition does not seem to be working. Can anyone tell me what i am doing wrong?
You can't do comparisons in Handlebars without a custom helper unfortunately.
I can't recall where I found this function, but I had a copy I was using in a node / express script to set the class based on a condition:
app.js
hbs template