Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pug: how do I include mixins across all pages?

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.

like image 280
Joel Hoelting Avatar asked May 18 '18 22:05

Joel Hoelting


1 Answers

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)
...
like image 159
Niklas Higi Avatar answered Oct 13 '22 03:10

Niklas Higi