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
nicoschuele
3,713 PointsUsing 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
Osaro Igbinovia
Full Stack JavaScript Techdegree Student 15,928 PointsYou 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.
Pean Shan Wu
5,557 PointsSomebody has the same question on stack overflow https://stackoverflow.com/questions/14170537/difference-between-include-and-block-in-jade
nicoschuele
3,713 Pointsnicoschuele
3,713 PointsNot really, no.
includeis useable in any file you want. From what I gathered from the doc,includewill include the whole file content while usingextendslet you only include content defined byblock. Blocks are more granular but my question was when do you use one over the other.