Generic template engine handler for Fractal, powered by consolidate.js


420.4.06 years ago6 years agoMinified + gzip package size for @frctl/consolidate-engine in KB


Consolidate Engine

Generic template engine handler for Fractal, powered by consolidate.js.

This engine is currently very experimental. If a specific Fractal template engine handler for your desired language is available then it is recommended to use that instead of this one as it will likely be easier to use and configure than this generic handler.

Currently specific template engine handlers have been implemented for:

Note: Due to the way that Consolidate handles loading of templates, this engine cannot be used for rendering pages, only components.


This engine comes pre-installed with Fractal, so there is no need to install it separately. However you will need to install whichever template engine you want to use via NPM.

As an example, to use Swig templates, first install swig:

npm i swig --save

Then add configuration details into your fractal.js file:

const fractal = require('@frctl/fractal');

fractal.engine('consolidate', '@frctl/consolidate-engine', {
    engine: 'swig' // The template language to use

fractal.set('components.engine', 'consolidate'); // use the consolidate handler
fractal.set('components.ext', '.swig'); // look for files with a .swig file extension

You can see a full list of supported template languages on the Consolidate documentation.

Template Engine Instances

You can customise the template engine instance in your fractal.js file if you want to add filters, globals, mixins etc before templates are rendered.

For example, to extend the above example to use a customised instance of Swig you could do the following:

const swig    = require('swig');
const fractal = require('@frctl/fractal');

// Add a custom Swig filter
swig.setFilter('join', function (input, char) {
  return input.join(char);

fractal.engine('consolidate', '@frctl/consolidate-engine', {
    engine: 'swig',
    instance: swig // Pass in the custom Swig instance
fractal.set('components.engine', 'consolidate');
fractal.set('components.ext', '.swig');

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.