Including parts of a diet template in another

Steven Schveighoffer schveiguy at gmail.com
Sun Mar 26 01:56:14 UTC 2023


On 3/25/23 4:56 PM, seany wrote:
> Hello
> 
> If we are creating a multipage Vibe.d application, we need to use diet 
> templates. I can't find any info on how to include parts or whole of a 
> diet template in another.

You can include an entire other diet template like:

```pug
include commondiv
```

Note that it gets copy-pasted as code, so it can use local 
symbols/functions you define in code islands.

I would also note that you can template the entire page (a common 
model), and allow other pages to inherit that common layout.

So something like:

layout.dt:
```pug
html
   head
     // stuff in head (always the same)
   body
     commondiv
       // always the same stuff here
     block content
```

page1.dt:
```pug
extends layout
block content
   // all the page1 specific content
```

Which is what I use. I also define `extraCss` and `extraJs` blocks to 
allow for more customization in those sections.

-Steve


More information about the Digitalmars-d-learn mailing list