www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Including parts of a diet template in another

reply seany <seany uni-bonn.de> writes:
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.

So for example, if i had pages :

1 =>

     ```
     html
       head
         //stuff in head
       body
         // a common div goes here
         .commonDiv
            // common div stuff here
         .first-page-specific-div
            // first page specific stuff ...


     ```

and

2 =>

     ```
     html
       head
         //stuff in head
       body
         // a common div goes here
         .commonDiv
            // common div stuff here
         .second-page-specific-div
            // second page specific stuff ...
     ```

I would like to do something like this

commonDivFile.extension =>

     .commonDiv
        \\ common div stuff goes here....
        \\ add css file affecting the common div
        \\ add javascript with event listeners for common div 
elements..

and then

1 =>

     ```
     html
       head
         //stuff in head
       body
         // some method to include commonDiv here, unknow to me
         .first-page-specific-div
            // first page specific stuff ...


     ```

and

2 =>

     ```
     html
       head
         //stuff in head
       body
         // some method to include commonDiv here, unknow to me
         .second-page-specific-div
            // second page specific stuff ...
     ```


I can't find a way to do this in documents. If it is in the 
documentation, please point me to it. I do not want to use an 
iframe.

What can be done in this case? Thank you.
Mar 25 2023
parent Steven Schveighoffer <schveiguy gmail.com> writes:
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
Mar 25 2023