Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Less: Can't use Map inside each

Tags:

css

less

I have following less:

@threshold:{
  a:50;
  b:200;
};

@themes:{
  a:red;
  b:blue;
};

.mymixin(@name,@color,@thrshld){
  //do-something
}

each(@themes,{
  .mymixin(@key,@value,@threshold[@key]);
});

By running the code, following error occurs:

RuntimeError: error evaluating function each: variable @key not found...

I'm using v3.9.0

How can I use Maps in each function?

like image 293
Omid Avatar asked Jul 07 '26 12:07

Omid


1 Answers

You need to use the @map[$@property] syntax to evaluate the value of @map[@property]

.mymixin(@name, @color, @thrshld) {
  .theme-@{name} {
    color: @color;
    width: @thrshld;
  }
}

@threshold: {
  a: 50;
  b: 200;
};

@themes: {
  a: red;
  b: blue;
};

each(@themes, {
  .mymixin(@key, @value, @threshold[$@key])
})
like image 70
henry Avatar answered Jul 10 '26 01:07

henry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!