gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:20:29 27 4
gpt4 key购买 nike

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

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

extends layouts/default
include includes/mixins

block content
+my_mixin('Hello World')

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

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

最佳答案

您可以包含 View 继承层次结构中更高层的 mixins,例如在 layouts/default.pug 的顶部。然后,mixins 将在所有 subview 的范围内可用。

include includes/mixins

doctype html
html(lang=$localeName)
...

关于javascript - Pug:如何在所有页面中包含 mixin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50420043/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com