I like ExpressJS but i don’t like the Jade template engine. Luckily it’s easy to change the template engine to something awesome like Handlebars!
This is how you use handlebars in Express.
Once you have your Express app up and running, you need to install the awesome view-engine by Eric Ferraiuolo called express3-handlebars
Here’s a step by step guide:
Open up a console and navigation to your Express app folder.
Then install express3-handlebars by typing: npm install express3-handlebars
Then modify your Express app to something like this:
1 | /** |
The importants parts being:
exphbs = require('express3-handlebars')
which will load the Handlebars module. And
1 | app.engine('handlebars', exphbs({ defaultLayout: 'main' })); |
which registers the view engine to be handlebars instead of Jade.
Once this is done you need a few basic Handlebars templates to see it working. You can try these to see it in action:
views/layouts/main.handlebars
1 |
|
views/home.handlebars
1 | <h1>Example App: Home</h1> |
For further documentation of express3-handlebars take a look the GitHub repo