最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Pug: how do I include mixins across all pages? - Stack Overflow

programmeradmin0浏览0评论

I have a file includes/mixins.pug that has some mixins. I also have a main layout file layouts/default.pug that I am extend-ing. How can I include those mixins in my layout file so that I don't have to write include includes/mixins on every page?

For example, this is what I have to do for each additional pug file. In this case: 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

How do I include the mixins in layouts/default.pug? I had trouble finding a solution in the documentation.

I have a file includes/mixins.pug that has some mixins. I also have a main layout file layouts/default.pug that I am extend-ing. How can I include those mixins in my layout file so that I don't have to write include includes/mixins on every page?

For example, this is what I have to do for each additional pug file. In this case: 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

How do I include the mixins in layouts/default.pug? I had trouble finding a solution in the documentation.

Share Improve this question edited May 19, 2018 at 12:25 Nemo 2,5822 gold badges31 silver badges64 bronze badges asked May 18, 2018 at 22:33 Joel HoeltingJoel Hoelting 1,9923 gold badges26 silver badges45 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You can include the mixins higher up in the view inheritance hierarchy, for example at the top of layouts/default.pug. The mixins will then be available in the scope of all children views.

include includes/mixins

doctype html
html(lang=$localeName)
...
发布评论

评论列表(0)

  1. 暂无评论