2016-09-01 1 views

Antwort

1

Grundsätzlich haben Sie Recht, aber das Schlüsselwort extend bietet Ihnen die Möglichkeit, Blockanweisungen zu verwenden. Sie können Standardblöcke aus einem erweiterten Layout in Ihrer Vorlagendatei überschreiben, wodurch sogar diese Layoutdatei erweitert wird. Alle geerbten Dateien, die durch das Schlüsselwort include in Ihrer Vorlage enthalten sind, können diese Blockanweisungen ebenfalls verwenden.

Hier ein kurzes Beispiel

layout.jade

doctype html 
html(lang='de') 
    head 
    // Default meta block 
    block meta 
     meta(charset="utf-8") 
     title This is the pagetitle 

    // Default block for css assets 
    block styles 
     style. 
     .somecss { 
     } 
    body 
    // Default block for the navigation 
    block navigation 
     ul.my_default_nav 
     li: a(href="template.html") Navitem 

    // Default content block 
    block main 

    // Default footer block 
    block footer 
     p Some copyright notes 

template.jade

extend layout.jade 

block meta 
    title This block overrides the default block statement 

block footer 
    p You can place your block somewhere in your template, during 
    | compile jade knows where to place it. 

block main 
    div 
    p Here you can place your default content it also will be 
     | replaced. 

Das Ergebnis all:

<!DOCTYPE html> 
<html lang="de"> 
    <head> 
    <!-- Default meta block--> 
    <title>This block overrides the default block statement</title> 
    <!-- Default block for css assets--> 
    <style> 
     .somecss { 
     } 
    </style> 
    </head> 
    <body> 
    <!-- Default block for the navigation--> 
    <ul class="my_default_nav"> 
     <li><a href="template.html">Navitem</a></li> 
    </ul> 
    <!-- Default content block--> 
    <div> 
     <p> 
     Here you can place your default content it also will bereplaced.</p> 
    </div> 
    <!-- Default footer block--> 
    <p> 
     You can place your block somewhere in your template, during compile jade knows where to place it.</p> 
    </body> 
</html>