Reputation: 93
I did a lot of searching on this topic and have found nothing that will help me out, it seems. I am trying to render header and footer using the block
and extends
feature of jade, rather than includes.
Here is what I have and I can't seem to understand why it will not render.
layout.jade
html
head
title= title
body
block header
block content
footer
block footer
index.jade
extends layout
block content
h1= title
p Welcome to #{title}
header.jade
extends layout
block header
h1 this is a header
footer.jade
extends layout
block footer
h2 this is a footer
Any help will be appreciated.
Upvotes: 1
Views: 650
Reputation: 3242
I think you're misinterpreting what 'extending a template' means. Each template that extends layout.jade
should be compiled into a page of its own. That is, layout
defines a blueprint for how each page that extends it should look. The inheritance pattern here does not go both ways: When seeing that the layout
template has a footer
block, pug does not search all other templates for possible block implementations. Instead, you tell it to compile child templates, like the index
template.
What I would suggest in your case is the following: Either have the footer and header content either directly included in layout.jade
, or include
it without the block
statement.
Do keep the index
template as is - IMHO, that's the correct usage pattern for template inheritance.
Upvotes: 2