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

Using Pug, when do you use extends with block rather than include?

I have an issue understanding when to use extends with block rather than include in pug templates. Are these two ways of building partials mostly interchangeable or is there a reason why you would use one way rather than the other?

2 Answers

You use 'extends' with 'block' because it is within that block(block content) you'll add special content (with your code) specific to a pug file. The 'include' is used only in one particular pug file which is the layout file(layout.pug), it is used to include headers and footers. All this various components in form of pug files is just to make your code neat and reusable by other developers. And in the case when there's a bug in your code, it'll be easy to pinpoint where that bug is.

Not really, no. include is useable in any file you want. From what I gathered from the doc, include will include the whole file content while using extends let you only include content defined by block. Blocks are more granular but my question was when do you use one over the other.