michael
michael

Reputation: 4483

Using a global wrapper template in Express/Jade

I've had a quick skim of the Jade documentation and I can't seem to figure out how to apply a wrapper to all templates that I output.

How is this usually done?

Upvotes: 0

Views: 457

Answers (1)

robertklep
robertklep

Reputation: 203231

It sounds like you want template inheritance:

// layout.jade
!!!5
html
  body
    block content

The content block is what you define in all templates that are going to inherit the layout template:

// index.jade
extends layout

block content
  h1 Hello World!

When you render index.jade, this is the result:

<!DOCTYPE html>
<html>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

So in layout.jade, you set up all common elements like JS/CSS, headers/footers, etc.

Upvotes: 2

Related Questions