Sass quick question (hopefully) here. Can you test for the existence of a mixin? e.g.
@if thumbnail-mixin {} @else { //define mixin }.
Ideally I'd use @unless
, but that only exists on a fork. I'm aware you can overwrite a mixin but I'm thinking more if you can have a default mixin, rather than having to specify N variables in every case.
I have been doing some googling and I currently understand the difference being that a variable stores a single line of information whereas, a mixin stores multiple lines of variables.
Defining a Mixin A mixin is defined with the @mixin directive. Tip: A tip on hyphens and underscore in Sass: Hyphens and underscores are considered to be the same. This means that @mixin important-text { } and @mixin important_text { } are considered as the same mixin!
CSS mixins Any CSS stylesheet, class or element that is defined in a Stylable CSS file can be used as a mixin source. You can use either a local class or element, or import the mixin from a different stylesheet. In the following example, a locally defined class is used as a mixin in the same stylesheet.
The most recent version of Sass (v3.3.0) has a mixin-exists
function:
.foo {
@if mixin-exists(mymixin) {
exists: true;
}
@else {
exists: false;
}
}
Sass v3.3 adds other existence tests too:
variable-exists($name)
global-variable-exists($name)
function-exists($name)
More on Sass v3.3.
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