

The concept of the partial is a piece of code that can be used one or more times on your page- it doesn't introduce anything new you couldn't do in the main template but is part of the DRY (don't repeat yourself) programming concept.Īndrew demonstrates that the process is recursive - that is a template can inherit code from many templates. Andrew says typically "the block is simply the place where the child template will inject its content." The `block` introduces the templating concept of **partials** or template fragments that are introduced into your code. The parent block can provide default content, if it makes sense for your purpose, though default content is purely optional. In a template, a block is simply a “block” of Pug template code that a child template may replace. You will use BOTH of these together to make great templates. The block and extends keywords are a little different. The block and extends keywords are conceptually similar and are used together to implement template inheritance and modularity. The base or the layout does most of the basic heavy lifting and the child template fills in the blanks of the template The layout or base template introduces the boilerplate of HTML, the nuts and bolts of the framework of the page which the child template depends upon. When extends is the first line in a child template, it is typically a layout that brings in a layout of blocks and "boilerplate" code.


In a template, using extends works to inject code and blocks from another file into the child template. Maybe someday I will write up a tutorial on this, but for now, I will simply write praise of this feature! Pug does all the standard things you would expect from a templating language but most impressive is that it supports inheritance. There are many templating languages for Node.js JavaScript, but Pug stands out with its deceptive simplicity while at the same time being expressive and powerful.
