I have a following mixin in Jade:
mixin indicator(slide_to, active)
- active = active || '' // this is an ugly method to create a default value
li(class=active, data-target='#' + CAROUSEL_ID, data-slide-to=slide_to)
and I call it like this:
+indicator(1)
+indicator(2, 'active')
I want the parameter active
to have a default value of ''
. I have found the ugly workaround as is shown in my codesample. Is there a better way to do this in Jade?
This example:
mixin test(slide_to, active)
li(class=active, data-slide-to=slide_to)
+test('a')
+test('a', 'b')
Compiles into this HTML for me:
<li data-slide-to="a"></li>
<li data-slide-to="a" class="b"></li>
I'm using Jade 0.35.0.
Jade doesn't add falsy values. You can read this in the Jade reference in the subchapter Boolean Attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With