Nunjucks and Sails JS

Rafael Rozon
1 min readNov 13, 2017

How to setup Nunjucks as the template engine of a Sails JS application

Nunjucks is a template engine build by Mozilla and it has a lot of functionality, for example, asynchronous control, filters, extensions, and many others. One of the most important features for me is template inheritance. That’s why I decided to use it in a Sails application that I’m building.

First things first. Install Nunjucks and Consolidate, which is the glue between Nunjucks and Sails.

npm install consolidate nunjucks --save

Then, in config/views.js replace the default values for the engine with the following:

If you want a different value for the extension (ext) is fine since you use the exact same extension for the files.

And just to illustrate template inheritance in Nunjucks, assuming this is the main template:

It can be extended in the following way:

--

--