Mixins allow you to create reusable blocks of Pug.
Mixins are compiled to functions, and can take arguments:
Mixins can also take a block of Pug to act as the content:
Mixins also get an implicit
attributes argument, which is taken from the attributes passed to the mixin:
The values in
attributes by default are already escaped! You should use
!= to avoid escaping them a second time. (See also unescaped attributes.)
You can also use mixins with
+link(class="btn") is also valid and equivalent to
+link()(class="btn"), since Pug tries to detect if parentheses’ contents are attributes or arguments. Nevertheless, we encourage you to use the second syntax, as you pass explicitly no arguments and you ensure the first parenthesis is the arguments list.
Default Argument’s Values
You can also set default values for you
arguments. Same as setting default function parameters in ES6.
You can write mixins that take an unknown number of arguments using the “rest arguments” syntax.