Pug: how do I include mixins across all pages?
Asked Answered
N

1

7

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.

Nigeria answered 18/5, 2018 at 22:33 Comment(0)
I
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)
...
Interviewee answered 19/5, 2018 at 12:43 Comment(1)
Thanks! Much appreciated!Nigeria

© 2022 - 2024 — McMap. All rights reserved.