Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Blocks and Extends in Jade layouts with Express not functioning

Blocks and Extends in Jade layouts with Express not functioning

Problem

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?

Problem courtesy of: Justin Beckwith

Solution

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.

Solution courtesy of: Justin Beckwith

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Blocks and Extends in Jade layouts with Express not functioning

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×