How can I extend jade layout from a view/parent/ch

2020-03-25 06:58发布

问题:

I have my Views structured like this

I wanted to extend the layout.jade to all jades under my user folder. Doing extends ../layout in the files under user folder doesn't work. There are no much writing about extending layouts that discuss about this.

Does Express allows this kind of extends?

回答1:

extends ../layout should work fine. Here is how I structure my views. What happens when you try to render the child template? Are you using blocks like I am, or includes?

// ls
+views
  +children
    -child.jade
  -layout.jade
  -sister.jade
-app.js

// layout.jade
!!!
html
  head
    script
      console.log('hi ho');
    block head
  body
    #wrapper
      block content

// sister.jade
extends layout
block append head
  style
    h1{ text-align: center}
block append content
  h1 Hello World

// children/child.jade
extends ../layout
block append content
  h1 Hello World