aelgoa
aelgoa

Reputation: 1201

sass include mixin as a parameter

I want to parametrize sass mixins to the extend that other mixins are passed as a parameters by name expanded inside it.

@mixin c(){color:red}

@mixin view($param){*{@include #{$param}}}

div{@include view}

The 2nd line and variations of it ive tried do not work and I haven't found any way to pass variables into the @include clause

Upvotes: 0

Views: 161

Answers (1)

Slawa Eremin
Slawa Eremin

Reputation: 5415

You can try to add some conditions inside mixin:

@mixin test1(){
  color: red;
}

@mixin test2(){
  color: blue;
}

@mixin view($param){
  .test{
    @if $param == 'test1'{
      @include test1();
    }

    @if $param == 'test2'{
      @include test2();
    }
  }
}

div{
  @include view(test1);
}

Upvotes: 1

Related Questions