How to count Sass mixin variable arguments

Viewed 208

I am trying to write a SASS mixin that outputs something different depending on how many variable arguments there are. Is there a way to count the number of arguments passed to a mixin?

@mixin my_func( $args... ) {
    @if count($args) === 4 {
        ... output here ...
    }

    @else {
        ... output here ...
    }
}
1 Answers

You can use the length function:

@mixin my_func( $args... ) {
    @if length($args) == 4 {
        ... output here ...
    }

    @else {
        ... output here ...
    }
}
Related