less / less.js

Less. The dynamic stylesheet language.
http://lesscss.org
Apache License 2.0
16.99k stars 3.41k forks source link

How to convert maps to variables? #3733

Closed tczzz closed 2 years ago

tczzz commented 2 years ago

I have a map, like below:

  #maps() {
    white: #fff;
    black: #000;
  }

Now, I want to convert it to some variable:

@white: #fff;
@black: #000;

But I don't know what to do, is there any way?

matthew-dean commented 2 years ago

"How to" questions are best posed on Stack Overflow. This is not a bug.

That said, this would be the solution:

#maps() {
  white: #fff;
  black: #000;
}
@white: #maps[white];
@black: #maps[black];
tczzz commented 2 years ago

Sorry, I didn't make it clear. When there are many attributes in the map, it is not easy to convert in this way. I tried like below but no success.

  each(#maps(), .(@v, @k, @i) {
    e(@)@{k}: @v;
  }

Is there a way not to set the variables one by one?