mercredi 26 décembre 2018

Using "each loop variables" inside if statement in SASS

I am trying to generate a bunch of styles through an each loop in SASS. The styles should only be generated, if the variable the each loop is looking at right now is set.

I tried different variable "styles", e.g.: $use-#{$type}, but I'm kinda lost.

$typo: (t1, t2);
$use-t1: 1; 
$t1-color: black;
$use-t2: 1; 
$t2-color: black;

/*FOR EACH TEST)*/
@each $type in $typo{
  @if $#{use-$type} == 1{ 
    .#{$type}{
      color: $#{$type}-color;
    }
  }
}

I would expect the variables in the first round of the each loop to be: $#{use-$type} -> $use-t1 -> 1 $#{$type}-color -> $t1-color -> black

But both throw "Expected identifier." or "Unknown variable", depending on how I try it.

Aucun commentaire:

Enregistrer un commentaire