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:
- Pertter
- Tinamre
But i want begin 1. Example:
- Pertter
- 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
Tim
2
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
Tim
4
That could work as well, but seems overkill for a increment
Happy coding!
1 Like