Conditional conclude rules
Let's say I have the following:
@import 'hello.less'
Based on the value of the variable, I want to nest this inside another class. In pseudocode, I want to do the following:
if(@someVar = true):
.someClass {
@import 'hello.less'
}
else:
@import 'hello.less'
I'm guessing I can use the mixing guards, but I don't know how to handle the "else" case:
.someClass when (@someVar = true) {
@import 'hello.less'
}
// Else?
source to share
Using not
and &
( &
expands to zero if its parent is global scope ( for example )):
@some-var: true;
.some-class when (@some-var) {
@import (multiple) "hello";
}
& when not(@some-var) {
@import (multiple) "hello";
}
Note that the import option is required in this case multiple
as both imports are always evaluated and the guards only control the content contained in the output or not.
---
Although in general I am wondering why you need to maintain code for different projects in the same file and control its compilation indirectly through variables. Instead, I suggest creating just a file with the names of the names:
.some-class {@import "hello";}
and import it unconditionally into the project you want this way.
source to share