How to use .html file extensions for handlebars in express? How to use .html file extensions for handlebars in express? express express

How to use .html file extensions for handlebars in express?


So I was able to do this by changing three things in my app.js file I hope this helps everyone out as much as it helped me!

var express  = require('express'),    exphbr   = require('express3-handlebars'), // "express3-handlebars"    helpers  = require('./lib/helpers'),    app = express(),     handlebars;// Create `ExpressHandlebars` instance with a default layout.handlebars = exphbr.create({    defaultLayout: 'main',    helpers      : helpers,    extname      : '.html', //set extension to .html so handlebars knows what to look for    // Uses multiple partials dirs, templates in "shared/templates/" are shared    // with the client-side of the app (see below).    partialsDir: [        'views/shared/',        'views/partials/'    ]});// Register `hbs` as our view engine using its bound `engine()` function.// Set html in app.engine and app.set so express knows what extension to look for.app.engine('html', handlebars.engine);app.set('view engine', 'html');// Seperate route.js filerequire("./routes")(app, express);app.listen(3000);


Agree with JemiloII,

  1. extname: '.myext' in the config while creating the expr-HBS instance (exphbr.create()) according to https://www.npmjs.org/package/express3-handlebars#-extname-handlebars-
  2. binding the expr-HBS engine to the extension: app.engine('myext', handlebars.engine); according to http://expressjs.com/3x/api.html#app.engine
  3. set the extension as view engine: app.set('view engine', 'myext'); - unfortunately no link to how it works.

Regards