Guide Customizing the layout with custom user fields

FateKid

DEVIL DID IT

Status

offline

Posts

14,666

Likes

125,808

Resources

3,373

Bits Credits

363

Admin

LEVEL

11

5,910 XP

This is a simple guide explaining how custom user fields can be used to customise the layout and allow members to have some form of control over the content, depending on the options you provide.

For the purposes of this guide, we will be creating a checkbox for members to opt out of seeing the forum statistics in the sidebar.


Create the custom user field

The first step is to create the custom user field, like so:

custom-user-field-png.png



A new option will then be present on the account preferences page.

preferences-png.png



Edit the widget

Now we enter a conditional statement in the widget display condition field to show the widget when the field is unchecked.
The code for that is:

Code:
!$xf.visitor.Profile.custom_fields.removeStatistics

widget-display-condition-png.png


Note how removeStatistics matches the ID of the custom user field.


That's it!
Any member who now checks the field in their preferences will no longer see the widget in the sidebar.

The same approach can be used for templates, forums, etc.
Just use the custom user field ID with a conditional statement to show/hide content.


If you found this tutorial useful, donations of positive emojis are gladly received. :cool:
 

Status

offline

Posts

49

Likes

83

Resources

3

Bits Credits

0

LEVEL

0

120 XP

Sorry, i just read your last sentence and start again from beginning.

Code like this very very new for me
Code:
!$xf.visitor.Profile.custom_fields.removeStatistics

Thanks anyway. I am still hold my head, reading this guide o_O
 
Liked by:

FateKid

DEVIL DID IT

Status

offline

Posts

14,666

Likes

125,808

Resources

3,373

Bits Credits

363

Admin

LEVEL

11

5,910 XP

Sorry, i just read your last sentence and start again from beginning.

Code like this very very new for me
Code:
!$xf.visitor.Profile.custom_fields.removeStatistics

Thanks anyway. I am still hold my head, reading this guide o_O
Unfortunately there is no online “list” of XenForo conditionals, there are guides to finding them through your src files.

I’ll upload a guide that explains more about this soon.
 
Liked by:

FateKid

DEVIL DID IT

Status

offline

Posts

14,666

Likes

125,808

Resources

3,373

Bits Credits

363

Admin

LEVEL

11

5,910 XP

Code like this very very new for me
Code:
!$xf.visitor.Profile.custom_fields.removeStatistics
$xf .visitor .Profile .custom_fields. .removeStatistics

I’ve color-coded the different pieces for this topic. Each colored section is essentially calling for information, explained below.

$xf - start off your conditionals

.visitor - who is this person to our server? This is used pretty much all around when you’re calling user-based information.

.Profile .custom_fields. - this one is pretty self-explanatory. We’re calling/pointing to the profile custom fields section.

.removeStatistics - remember when we created the custom user field from the Admin CP?
Create the custom user field

The first step is to create the custom user field, like so:

custom-user-field-png.png
You’re using that information to call this section from before.

I hope this helps you learn a bit about XenForo Conditionals!
 

Latest threads

Forum statistics

Threads
53,919
Messages
83,957
Members
50,527
Latest member
DarkStarLegend
Top Bottom