How to use Underscore templates instead of Jade in Express? How to use Underscore templates instead of Jade in Express? express express

How to use Underscore templates instead of Jade in Express?


Use consolidate.js to convert Underscore's template functions to accept the format Express requires in 3.x (path[, locals], callback).


First, you are calling app.engine with an extension name and an object whereas it takes a function as second parameter (see source documentation).

This function has 3 parameters : the path to the file, options and the callback.

As, written in the documentation, it's advised to use consolidate.js as an helper to use template engines that are not express friendly.

Here a simple integration of consolidate.js quoted from its README and adapted to use underscore:

// assign the swig engine to .html filesapp.engine('html', cons.underscore);// set .html as the default extension app.set('view engine', 'html');

Also, I don't know how to handle your layout.html with underscore under Express, I don't think it's possible out of the box.


var cons = require('consolidate');

// view engine setup

app.engine('html',cons.underscore);app.set('views', path.join(__dirname, 'views'));app.set('view engine', 'html');

in terminal

npm install consolidate --save