XF 2.2 Conditional statement question

alternadiv

Well-known member
I have a custom style property that I want to only apply if the visitor is not logged in. Shouldn't this work for that?
<xf:if is="property('alternadivUsernameLinks') AND !{$xf.visitor.user_id}">

Edit: The above code does work. I was testing the wrong version of the style.
 
Last edited:
It's not really clear where you're applying that but the condition only needs to evaluate against the logged in status.

This will execute whatever is in the if statement only for guests.
HTML:
<xf:if is="!$xf.visitor.user_id">
    Do stuff
</xf:if
 
It's not really clear where you're applying
Unlinking usernames for guests. The CSS itself works but it is applying to guests and users.

CSS:
<xf:if is="property('alternadivUsernameLinks') AND !{$xf.visitor.user_id}">
.username {
    pointer-events: none;
}
</xf:if>

but the condition only needs to evaluate against the logged in status
So do it like this?

CSS:
<xf:if is="!{$xf.visitor.user_id}">
<xf:if is="property('alternadivUsernameLinks')">
.username {
    pointer-events: none;
}
</xf:if>
</xf:if>
 
You can't use conditional statements in less templates.

You can use [data-logged-in="false"] though and for the property you would just use the regular class name and apply the styling.
 
I have a custom style property that I want to only apply if the visitor is not logged in. Shouldn't this work for that?
<xf:if is="property('alternadivUsernameLinks') AND !{$xf.visitor.user_id}">

Edit: The above code does work. I was testing the wrong version of the style.
For anyone reading this thread in the future, the original code I had actually does work. I was testing the wrong version of the style like a silly idiot.
 
Back
Top Bottom