Evgeny
Evgeny

Reputation: 107

Start {{@index}} on 1 and not 0 in Handlebars, no template

I am looping through items using @each, and I want to start with index 1 and not 0. I have tried something like

var Handlebars = require('handlebars');

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

and then

{{inc @index}}

But when I am loading the page, it says

Error: Missing helper: "inc"

What is another way to do it?

Upvotes: 0

Views: 2749

Answers (1)

fadly
fadly

Reputation: 11

in your app.js :

app.engine('.hbs', expressHbs({ defaultLayout: 'layout', extname: '.hbs', helpers: {
  inc: function(value, options){
    return parseInt(value) + 1;
  }
} }));

Upvotes: 1

Related Questions