Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics (2015) Using Templates with Express Scaffolding Your Project’s Templates

Tim Mendoza
Tim Mendoza
5,878 Points

'block content' in index.jade

In index.jade, is 'block content' supposed to go on line 2, just under 'extends ./layout.jade'?

4 Answers

Jess Hines
Jess Hines
5,411 Points

Yes it is. I had to struggle with this a bit too, as it's different from other template languages. But on the template being extended, block content says where to put any other template output, and on the template that uses an extends block content defines the markup that will override the block content section of the template that is being extended.

Josh Cummings
Josh Cummings
16,310 Points

Thanks! This helped me out too. Was getting an error until I threw in that block content under extends.

Matthew Day
Matthew Day
6,740 Points

Thank you for pointing out this error. Saved me a lot of time.

Yeah I don't understand how Huston got this to work without adding "block content" to the index.jade file

I was having errors until I looked at the code in the next video and saw I was missing it.

Leigh Maher
Leigh Maher
21,830 Points

Maybe I don't understand exactly what 'block content' does but it seems a bit redundant to me. Surly, this line gives us all the information the template needs. It simply calls the template into file at that point, and we're done.

extends ./layout.jade

I don't get what 'block content' does at this point? And I don't get what it's doing at the the bottom of the layout.jade file either?

Matthew Day
Matthew Day
6,740 Points

I am new to this as well but extends ./layout.jade and block content are doing two different things. My understanding is extends basically says that that file now has the ability to inherit from another file (in this case, index.jade can now inherit from layout.jade). Huston doesn't say this explicitly but it appears that block content needs to be present in both the file that inherits and in the file that passes its code along. In the file that inherits (i.e. index.jade), block content says where the inherited code should go. In the file that passes its code along (i.e. layout.jade), block content says "pass in all the code above this line to the file that inherits."

Dennis Brown
Dennis Brown
28,742 Points

This drove me crazy for so long, as he never shows adding the block content to the index, but it's necessary to work.

There really should be an addendum to the video. I didn't figure this out until I finally decided to move forward hoping some answer would surface, and after seeing the post template worked, deciding to see if adding the missing code to the index would work.