Blocks not working with nodejs and jade
Pregunta
Reading for hours, I am pretty sure I understand how blocks in Jade work. Here is my layout.jade
file:
!!! 5
html(lang="en")
head
title= title
link(rel= 'stylesheet', href= '/style.css')
body
h1 Placeholder Title
block content
And my index.jade file
extends layout
block content
p Hello World
However, when I visit index.jade
the only thing that shows up is
"Placeholder Title"
The "content" block in layout.jade
never gets replaced by the content block in index.jade
Solución
For blocks to work you need to do { layout: false }. More information can be found in the docs: https://github.com/visionmedia/jade#template-inheritance
Otros consejos
I don't see your route-handling code, but I assume you are doing:
res.render('layout')
instead of:
res.render('index')
You have to render index.jade (the file that extends
the layout), and not layout.jade (which is like the "base class").
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow