3

Is it possible to refer to a variable with another variable in Sass? I want to do something like this:

$gray = #ccc;
$white = #fff;

@each $color in gray, white {
    div_#{$color} {            // works fine
        color: #{$#{$color}};  // fails
    }
}

I tried all the variations I could think of to get the interpolation to work and no dice. Anyone know if it's possible? Thank you!

glortho
  • 13,120
  • 8
  • 49
  • 45
  • 1
    Not sure if this is still relevant: http://stackoverflow.com/questions/6354613/using-hash-with-scss – cimmanon Sep 18 '12 at 19:51
  • Thanks for pointing me to this. I fear it's the same now, though I'll keep it up just in case. – glortho Sep 18 '12 at 19:58
  • It is not possible. The link above is accurate. – Miriam Suzanne Sep 18 '12 at 20:37
  • 1
    It's probably also worth noting that according to this post from Compass creator and Sass co-author Chris Eppstein, this ability is coming "in the future": Maps - An new data type for storing an association between a key and a value. This will help us implement variable arguments for keyword-style arguments as well as address a very common request for "variable interpolation". http://chriseppstein.github.com/ – Jackie Sep 25 '12 at 03:22

1 Answers1

5

Sass now has maps, so you can do:

$colors: (gray: gray, white: white);

then loop through it.

But you can't interpolate within interpolations.

sam
  • 40,318
  • 2
  • 41
  • 37
  • Not exactly what I was looking for, but works! Nice addition to Sass, thx. BTW I'd do `$colors: (gray: #ccc, white: #fff)` – glortho Jun 16 '14 at 14:31