【问题标题】:Pug: how do I include mixins across all pages?Pug:如何在所有页面中包含 mixins?
【发布时间】:2018-05-18 22:33:00
【问题描述】:

我有一个文件includes/mixins.pug,其中包含一些混入。我还有一个主布局文件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')

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?我在文档中找不到解决方案。

【问题讨论】:

    标签: javascript html pug


    【解决方案1】:

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

    include includes/mixins
    
    doctype html
    html(lang=$localeName)
    ...
    

    【讨论】:

    • 谢谢!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-03-06
    • 2015-07-08
    • 2012-09-15
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多