1

I am looking for a way to generate variables dynamically from a sass map. So far I have looked into multiple examples, but all use a function like weight(map-get($map, 'key')) to get what is wanted. Instead I would like to generate the variable. For example

font-weight:$__weight--thin;

Notice the variable above. I would like to generate from a sass map like below:

//Font Weights
$__map--font-weights:(
    xthin:     100,
    thin:      200,
    light:     300,
    regular:   400,
    medium:    500,
    semibold:  600,
    bold:      700,
    xbold:     800,
    xxbold:    900
);

This map should spit out variables like:

$__weight--thin:  200;
$__weight--light: 300;
...

So far this is what I have:

@mixin makeWeights() {
  @each $key, $value in $__map--font-weights {
    $#{key}: $value
  }
}
justin.esders
  • 1,316
  • 4
  • 12
  • 28
  • Sass does not allow variables to be created or accessed dynamically. https://stackoverflow.com/questions/8533432/creating-or-referencing-variables-dynamically-in-sass – anderssonola Aug 20 '18 at 08:24

0 Answers0