Reputation: 3309
How I can use a variable in another variable? How I can do this:
$buttons: default, success, primary, info, warning, danger;
$default_color: #aaa;
$success_color: #bbb;
$primary_color: #ccc;
$info_color: #ddd;
$warning_color: #eee;
$danger_color: #fff;
@each $b in $buttons {
.btn-#{$b} {
color: $#{b}_color;
}
}
Upvotes: 3
Views: 606
Reputation: 1064
The way you are looking doesn't implement in SCSS yet but you can do something like this:
$default_color: #aaa;
$success_color: #bbb;
$primary_color: #ccc;
$info_color: #ddd;
$warning_color: #eee;
$danger_color: #fff;
$buttonsList:
"default" $default_color,
"success" $success_color,
"primary" $primary_color,
"info" $info_color,
"warning" $warning_color,
"danger" $danger_color;
@each $b in $buttonsList {
.btn-#{nth($b, 1)} {
color: nth($b, 2);
}
}
Sassmeister link.
Upvotes: 3
Reputation: 1430
Sass does not allow variables to be created or accessed dynamically. Use map instead http://sass-lang.com/documentation/file.SASS_REFERENCE.html#maps Example: https://stackoverflow.com/a/17978519
Upvotes: 1