LESS CSS defines variables when another variable is true

I used security expressions elsewhere in my CSS to retrieve IF statements in LESS, however they do not work for me when trying to declare such variables ...

@neutral: false;
@warm: true;

when (@neutral = true) {
    @green: #91C95B;
    @red: #F15647;
    etc...
}
when (@warm = true) {
    @green: #91AD3C;
    @red: #BF2A23;
    etc...
}

This is an example of how I would like to use this variable.

h1 {
    color:@green;
}

This is how I expected it to compile before CSS

h1 {
    color: #91AD3C;
}

Is this possible with LESS or will I need to change my code in order to use security devices for mixing?

+4
source share
1 answer

You can use Guarded Mixinsas follows:

@neutral: false;
@warm: true;

.color() when (@neutral) {
    @green: #91C95B;
}
.color() when (@warm) {
    @green: #91AD3C;
}
.color();


h1 {
    color:@green;
}
+4
source

All Articles