Add layout and partial support to consolidate.js!

Comprise add layout and partial support to consolidate.js!

Comprise add layout and partial support to the great consolidate.js template engine.

  • Add layout support to your templates, incl.
    • Default templates
    • Template hierarchies
    • "no template" option.
  • Partials could use the origin and optional a new variable scope.

Tested with:

Doesn't work yet with:

  • haml -- ! layout('default') and != partial('partial1') does not work. Support welcome!
  • mustache -- {{{ layout 'default' }}} and {{ partial("partial1") }} does not work. Support welcome!
var Comprise = require('comprise').Comprise;
var comprise = new Comprise({
    engine: 'jade',
    layout: 'default',
    templateDir: __dirname + '/views'
comprise.render('your jade file', { user: user }, function(errresult) {
    if (err) {
    } else {

Available options:

  • engine - See consolidate.js engine list
  • layout - Optional default layout
  • extension - file name extension, default is simular to engine
  • templateDir - Required
  • layoutDir - Optional, default is $templateDir/_layout
  • partialDir - Optional, default is $templateDir/_partials

express framework integration

var comprise = require('comprise');
    engine: 'jade',
    layout: 'default'
app.set('view engine', 'jade');

Available options see API section above.

templateDir was automatically set based on the express setting views (default ./views).

Just render content.jade, but use the common default.jade template which extends the layout.jade.

content.jade template:

h1 This content use the standard layout!
    != partial('partial1')
    != partial('partial2.jade')

layout.jade layout:

        title comprise
        != content()

default.jade included layout:

= layout('layout')
    nav navigation code
!= content()

Comprise provides a simple wrapper around consolidate.js and add four small functions to the local template variables:

  • layout(layout)
  • nolayout()
  • content()
  • partial(partialTemplate, partialVariables)
npm install comprise --production
npm install --save-dev
npm test