Answer the question
In order to leave comments, you need to log in
Mixin vs. Include in Pug?
What is the best approach for reusing different markup structures in Pug.js, for example when using a component approach in layout? Let's say we have a button that could be:
button.btn.btn--default Submit
button.btn.btn--disable Send
...
mixin btn(type)
button.btn(class=`btn--${type}`) Text
and stick it in the right places:+btn('default')
+btn('disable')
include
?btn-default.pug
btn-disable.pug
Answer the question
In order to leave comments, you need to log in
Parameters are explicitly passed to the mixin, and this is a great happiness. If you try to emulate mixins with includes, you will quickly run into code like this:
- var buttonTitle = "кнопка";
- var buttonSmall = "small";
- var buttonType = "danger";
- var icon = "trash";
include 'includes/button'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question