postcss-advanced-variables icon indicating copy to clipboard operation
postcss-advanced-variables copied to clipboard

Can't use variables for custom property names in @each loops

Open spaceninja opened this issue 6 years ago • 1 comments

I'm trying to set up an each loop to render a list of layers as custom properties that we'll use for z-index values in our pattern library. However, I can't find a way to get the layer variable to render as a custom property name.

Here's a test case:

$layers: alpha, beta, gamma, delta;

:root {
  @each $layer $i in $layers {
    --#{$layer}: $i;
  }
}

.beta {
  z-index: var(--beta);
}

spaceninja avatar Apr 17 '19 22:04 spaceninja

You might want to check out https://github.com/outpunk/postcss-each which works for me (although the syntax is a little different).

So far my experience with this plugin has been quite buggy. The examples in the README don't work.

yangshun avatar Apr 17 '19 22:04 yangshun