Pug:如何在所有页面中包含 mixin?

Joe*_*ing 5 html javascript pug

我有一个includes/mixins.pug包含一些 mixin的文件。我也有一个主要布局文件layouts/default.pug,我extend-ing。我怎样才能在我的布局文件中包含这些 mixin,这样我就不必include includes/mixins在每一页上都写?

例如,这就是我必须为每个额外的 pug 文件做的事情。在这种情况下:new_page.pug

extends layouts/default
include includes/mixins

block content
  +my_mixin('Hello World')
Run Code Online (Sandbox Code Playgroud)

layouts/default.pug

doctype html
html(lang=$localeName)
  block vars
  head
    meta(charset="UTF-8")
    meta(http-equiv="X-UA-Compatible" content="IE=edge")
    meta(name="viewport" content="width=device-width, initial-scale=1.0") 

    block styles
    link(rel="stylesheet" type="text/css" href="/assets/css/styles.min.css")
  body
    block content
Run Code Online (Sandbox Code Playgroud)

我如何在 中包含mixin layouts/default.pug?我无法在文档中找到解决方案。

Nik*_*igi 5

您可以include在视图继承层次结构中更高的位置,例如在layouts/default.pug. 然后,mixin 将在所有子视图的范围内可用。

include includes/mixins

doctype html
html(lang=$localeName)
...
Run Code Online (Sandbox Code Playgroud)