teggy
teggy

Reputation: 6335

Jade template inheritance without Express

I would like to use Jade block inheritance but I'm not sure how to do that if I'm not using Express. According to the Jade doc, I can use block inheritance in Express by simply adding app.set('view options', { layout: false });. How can I achieve this without Express?

https://github.com/visionmedia/jade

Upvotes: 0

Views: 1690

Answers (1)

Jonathan Lonowski
Jonathan Lonowski

Reputation: 123563

You don't need Express at all to use Jade's Template inheritance; you only need Jade:

// app.js
var jade = require('jade');

var options = { pretty: true, locals: {} };

jade.renderFile(__dirname + '/home.jade', options, function (err, html) {
    console.log(html);
});
// home.jade
extends core

block body
  h1 Home
// core.jade
doctype html
html
  head
    meta(charset='utf-8')
    title Foo
  body
    block body

Another example can be found in the repository:

The reason the Jade docs mention setting the 'view options' for Express 2.x is because Express' own (and now defunct in 3.x) layouts are a competing feature that should be disabled to prevent conflicts when using Jade's inheritance.

Upvotes: 1

Related Questions