I wonder if there is a better solution (or if my solution is even right), to create if statement like behavior with variables and guards.
Goal:
- If variable is set to true, compile the code (works)
- If variable is set to anything else, ignore the code (default, works)
- Keep initial code position (dosnt work, is merged wherever
.responsive (@responsive);
is called)
My Code:
@responsive: true;
.responsive(true){
a {
color: red;
}
}
.responsive(true) {
b {
color: blue;
}
}
.responsive (@responsive);
I am not completely sure I understand what you say doesn't work.
But if I do ... there are two things connected to this that you have to bare in mind in LESS:
that said - if you really want to use the same guard in multiple places to do different things, you would need to define multiple mixins (each place would get another mixin), and if you want to render it in the place you define it, you would just need to call it immediately after (or before) you define it. Something like this:
the output will be:
So the mixins
.a()
and.b()
are returned if@responsive
is set totrue
, if not you get:I hope this is kinda what you wanted.