Custom Profile Preference Field Conditional

Russ

Well-known member
#1
How exactly would you turn this into a working conditional? Basically I'm doing a simple profile field to allow users to choose their width of the website without having multiple styles

ex1.png
ex2.png

I've tried something simple like this for the purposes of testing to see if it would output anything:

Code:
<xen:if is="{$user.customFields.pagewidth} == 'Fluid Version'">
fluid is a go
</xen:if>
<xen:if is="{$user.customFields.pagewidth} == 'Fixed Version'">
fixed is a go
</xen:if>
and also:

Code:
<xen:if is="{$user.customFields.pagewidth} == 'preffluid'">
fluid is a go
</xen:if>
<xen:if is="{$user.customFields.pagewidth} == 'preffixed'">
fixed is a go
</xen:if>

I also noticed a setting in user fields "Value Display HTML" which seems like I might be able to expand on what I'm trying to achieve but I'm a coding noob sometimes. Thanks ahead of time for any help.
 

Russ

Well-known member
#3
You probably want $visitor, not $user. $visitor is the current logged in user.
Got that part figured out earlier after some troubleshooting, my next question is how would the setting work with a single check box?

Code:
<xen:if is="{$visitor.customFields.pagewidth} == 'on'">
fluid is a go
</xen:if>
 
#5
I'm also trying to add the choice of forum width. But where would i add the {$visitor.custom.xxx} at the end?
Using it in xenforo.css doesn't seem to work.

Thanks in advance!
 

Chris D

XenForo developer
Staff member
#6
You can't use HTML in CSS.

Something like this would work:

<xen:if is="{$visitor.customFields.pagewidth.on} == 'on'">
<style>
.pageWidth
{
width: 900px;
}
</style>
</xen:if>

Or instead of <style> tags you could require a different CSS file that you create yourself.

So instead of the style tags it would look like this:

<xen:if is="{$visitor.customFields.pagewidth.on} == 'on'">
<xen:require css="fixedwidth.css" />
</xen:if>
 
#10
@Chris D @Russ
I'm trying to achieve the same but the conditional doesn't work. I want to set a conditional and display a text depending on the user selection:
1519269731577.png
1519269852482.png
Current user selection:
1519269798237.png



1519269827711.png

The conditional above isn't working. Any idea why it isn't displaying the text even when the user has set ambassador_gold option?
The template where the conditional was set is message_user_info
 

Steve F

Well-known member
#11
Do you have the show custom fields option selected in the style properties: Style Properties > Message Elements > Show Custom FIelds ?
 

Steve F

Well-known member
#13
Oh, right you would want to use $user if you want to display something in a message of that user. $visitor to display something to the visitor if their custom field is that choice.
 
Top