Justin Beckwith
Justin Beckwith

Reputation: 7866

Blocks and Extends in Jade layouts with Express not functioning

I have a small express site written for node. I'm using Jade for layouts, and trying to get a handle on the new extends/block bits. When I use the standard layout/child view pattern list here, everything works great:

https://github.com/visionmedia/express/blob/master/examples/jade/views/layout.jade

I want to get fancy and use blocks to stuff custom html into specific parts of the master layout. So I transitioned over to something that looks more like this:

https://github.com/visionmedia/jade/blob/master/examples/extend-layout.jade

https://github.com/visionmedia/jade/blob/master/examples/extend.jade

Using the exact code in the extend-layout example above, my pages will always render the extend-layout.jade part, but never the content inside. Anything inside of a block never seems to get rendered. I've given this a try, but it doesn't help:

https://github.com/visionmedia/jade/issues/377

I'm running node 0.6.2, express 0.2.5, and jade 0.18. Any takers?

Upvotes: 1

Views: 5316

Answers (2)

Julian Knight
Julian Knight

Reputation: 4923

The layout config entry is deprecated now anyway with v3 of Express.

You can only use the block/extends style.

Upvotes: 1

Justin Beckwith
Justin Beckwith

Reputation: 7866

So I've figured out what was up. I was manually specifying the layout to use in express - I was setting it to the correct layout, but removing that line solved the problem. Example (for others who run into this):

exports.index = function(req, res){
  res.render('index', { title: 'Express' })  // this works!
  res.render('index', { title: 'Express', layout: 'layout' }) // this doesn't work
};

I would have expected a different behavior - including an explicit layout like this simply caused the child view to not render within the master layout.

Upvotes: 0

Related Questions