XF 2.0 LESS "when" is not working

CMTV

Well-known member
I have created my custom style variable questionthreads_isStylingBestAnswerUserBg. It has Boolean value type. It is set to true.

Now in my LESS template I have this code:
Less:
.container when (@xf-questionthreads_isStylingBestAnswerUserBg = true) {
    background: #000;
}

The problem is that this code is not working.

It is really strange for me because this variant is working fine:
Less:
@test: true;
.container when (@test = true) {
    background: #000;
}

It seems that @xf-questionthreads_isStylingBestAnswerUserBg returns something weird... What is wrong in my code?

Other style variables (colors, numbers) are all working fine. The problem appears only when I use "when".
 
It's important to note that style properties are not true LESS variables. In this case, I suspect it will be treated as "1" if true and an empty string if false, as it's a PHP boolean value, not a LESS boolean.

There wasn't really a direct expectation of boolean properties being used in LESS like that -- they're more for templates. In terms of that approach, I think a better approach would be to define a class to change the styling and then use the style property to control whether that class is applied within a template. This is likely more flexible and clear.

However, I will look into whether we can make a change here if you use a boolean in LESS directly.
 
Back
Top Bottom