如何在jade中定义默认/回退块

meo*_*meo 2 node.js pug

我的布局看起来像这样:

body
    header.l-header.l-site-width
        block header

    // include the block with the name body form whatever file that uses layout
    .l-body.l-site-width   
        block body

    footer.l-footer.l-site-width
        block footer
Run Code Online (Sandbox Code Playgroud)

现在我没有在使用布局的文件中指定标题块,我想使用默认包含.

我试过了:

block header || "something else"
Run Code Online (Sandbox Code Playgroud)

在最好的情况下:

block header || include ../partials/base/header
Run Code Online (Sandbox Code Playgroud)

它不起作用,但不会产生错误.知道怎么做吗?

Sas*_*olf 6

实际上,您只需在标头块中编写默认代码即可.

block header
  include ../partials/base/header
Run Code Online (Sandbox Code Playgroud)

如果现在扩展布局,可以使用简单的独立block语句覆盖块的内容.

extends layout

block header
  ... your code ...
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用appendprepend添加到块中,在这种情况下,旧内容仍然存在.