I'm starting a project using sass and I prefer to write it in .sass
syntax.
Also I would like to use the map feature in order to declare some key-value
variables...
as the example:
$primary-colors: (
"red": "#ff0000",
"green": "#00ff00",
"blue": "#0000ff"
);
/* Key and value together */
@each $color in $primary-colors {
.thing {
content: "#{$color}";
}
}
/* Key and value separate */
@each $color-name, $color-code in $primary-colors {
.color-#{$color-name} {
background: $color-code;
}
}
My issue is that I could not find how to write those map
variables in .sass
syntax.
I already tried something like:
$primary-colors: (
"red": "#ff0000"
)
$example: map-get($primary-colors, "red")
And I get this error when I try to compile it:
Error: Illegal nesting: Nothing may be nested beneath variable declarations.
My sass version is:
Sass 3.4.11 (Selective Steve)
Does anyone know how to use it like .sass
syntax?
Well, this is a problem which goes with
.sass
syntax as a free feature. You can join a discussion about it on github. But it's just a pointer to the well-knownmultiline-issue
, and it is also discussed on github.What you can do about that? Just use one-liners. And
map-merge
function for long declarations. Read about it in the docs.The output will be: