SASS Q: Can we pass mixins as argument/parameter?

SASS Q: Can we pass mixins as argument/parameter?
0

#1

Im playing around SASS for now and been loving mixins. And Ive been experiencing writing media queries and feature queries a lot. And i just thought if i could make the code more readable. Ive been googling, and but i think it isn’t possible. Am I right?

So I’ve tried these:

  • returning as a function

sass

@function grid-support($mixin)
  @return #{
      @supports(display: grid)
           $mixin 
   }

@some-mixin()
    body
        display: grid

grid-support(@include some-mixin())

//syntax error
  • as a mixin

sass

@mixin grid-support($mixin)
   #{
        @supports (display: grid)
            @include $mixin
    }

@some-mixin()
    body
        display: grid

@include grid-support(some-mixin())

//wrong again

Thank you in advance for sharing your thoughts about this. :slight_smile:


#2

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

Thank you Randell, I thought I need to specify the language, turns out, it isn’t needed