0

I'm want to make a variable from a list item, but i can't find a method to paste a dollar sign a front of it. Beneath are the methods that i tried.

$hoi: yellow;
$test: hoi;

helpMe{
  background: $#{$test}; //error
  background: $$test; //error
  background: $nth($test, 1); //error
  background: unquote("$")#{$test}; //output: $hoi
  background: unquote("$")nth($test, 1); //output: $ hoi
};

Is there any method to paste a dollar sign before a variable and still get recognized as a variable?

Lemnis
  • 462
  • 3
  • 13

2 Answers2

0

With pure SASS, you can't declare variables with names taken from other variables.

You can only do that using a template to generate Sass code and then parse it.

Here's an example of how Compass does it for generating sprite variables: https://stackoverflow.com/a/16129685/901944

Bun i strongly advise against it. This is poor practice that leads to spaghetti code that's difficult to maintain. In most cases you can manage without that approach.

Community
  • 1
  • 1
Andrey Mikhaylov - lolmaus
  • 23,107
  • 6
  • 84
  • 133
0

yes you can set make a variable from a list item.

for example:-

font: #{$font-size}/#{$line-height};

and in your case:-

$hoi: yellow;
$test: hoi;

helpMe{
  background: #{$test};
};
JA9
  • 1,708
  • 3
  • 14
  • 18