Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variables in Handlebars

I'm passing models to a handlebars template and putting a few of the properties in a row. I want to have some sort of position variable for each row. Specifically, I want to know how many rows have been created and have a position associated with each row.

e.g.

{{#each row}}
<span class = (indexHere)>
  <tr>
     <td> <{{this.property}}>
  </tr>
</span>
{{/each}}
like image 942
praks5432 Avatar asked Jul 26 '12 23:07

praks5432


2 Answers

This is an old question and maybe at that time Handlebars did not include the @index property, but according to current (1.3.0) documentation:

When looping through items in each, you can optionally reference the current loop index via {{@index}}

like image 141
AsGoodAsItGets Avatar answered Oct 05 '22 08:10

AsGoodAsItGets


You make your own helper :-)

Here's one you can steal: https://gist.github.com/1048968

like image 35
machineghost Avatar answered Oct 05 '22 10:10

machineghost