0

I want to put the serial no. in the table inside the #each loop, In the .hbs file I tried this:

{{#each item}}
    <tr>
        <th>{{@index}}</th>
    <tr>
{{/each}}

But this prints the index from 0, I want to start it from 1, How do I do it?

Sojo C Johny
  • 126
  • 8
  • Does this answer your question? [Adding offset to {{@index}} when looping through items in Handlebars](https://stackoverflow.com/questions/22103989/adding-offset-to-index-when-looping-through-items-in-handlebars) – raina77ow Jul 29 '22 at 17:40

1 Answers1

0

a helper function that lets you perform calculations on expressions like addition and subtraction etc.

Below function registers a new helper, which simply increments a value by 1:

var Handlebars = require('handlebars');

Handlebars.registerHelper("addOne", function(value, options)
{
    return index + 1;
});

You can then use it within the handlebar expression using the addOne keyword, like:

{{addOne @index}}
Rafnas
  • 1
  • 2