Increment @index on #each in template

Hi,
I have a problem that I need help with, I searched the forum but haven’t mentioned
I have a template:

{{#each customers}}
 <p>{{@index}}. {{this.name}}</p>
{{/each}}

This code is run fine, and show list name with @index begin zero. Example:

  1. Pertter
  2. Tinamre

But i want begin 1. Example:

  1. Pertter
  2. Tinamre
I rewrite code with @index + 1, but not working:
{{#each customers}}
  <p>{{@index + 1}}. {{this.name}}</p>
{{/each}}

How to print it out with @index + 1.
Thanks.

1 Like

Don’t know if the @index is exported as another var in the js environment, but something like this should be possible in a js block:

{{js "parseInt(@index) + 1"}}
3 Likes

I just got to know another way:

Template7.registerHelper('increment', function (value){
  return value + 1;
});

then:

{{increment @index}}

But it seems more complicated than your way.
Thanks for the support. Template7 is a great framework.

1 Like

That could work as well, but seems overkill for a increment :slight_smile: Happy coding!

1 Like