The problem is that you are using two different viewing mechanisms. express-handlebars and hbs .
Your files are .hbsdisplayed using express-handlebars, while you register the assistant before hbs.
Using hbs
Drop express-handlebarsand leave this line:
app.engine('.hbs', expressHbs({ defaultLayout: 'layout', extname: '.hbs' }));
.hbs hbs:
hbs . .hbs res.render.
app.set('view engine', 'hbs');
hbs.registerHelper('if_equal', function(a, b, opts) {
if (a == b) {
return opts.fn(this)
} else {
return opts.inverse(this)
}
});
express-handlebars
const expressHbs = require('express-handlebars');
const hbs = expressHbs.create({
helpers: {
if_equal: function(a, b, opts) {
if (a == b) {
return opts.fn(this)
} else {
return opts.inverse(this)
}
}
}
});
app.engine('.hbs', expressHbs({extname: '.hbs'}));
app.set('view engine', '.hbs');