Customising the layout with custom user fields xenforo 2

A

AdminAdmin is verified member.

Well-Known Member
Staff member
Administrator
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:

50526509743_1cda5d73d5_o.png




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

50527394112_90ab0085ca_o.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

50527238926_da42f9224f_o.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.
 

Facebook Comments

Similar threads

A
Replies
0
Views
925
AdminAdmin is verified member.
A
A
Replies
0
Views
868
AdminAdmin is verified member.
A
A
Replies
0
Views
707
AdminAdmin is verified member.
A
A
Replies
0
Views
927
AdminAdmin is verified member.
A
A
Replies
0
Views
6K
AdminAdmin is verified member.
A
A
Replies
0
Views
3K
AdminAdmin is verified member.
A
T
Replies
2
Views
4K
AdminAdmin is verified member.
A
A
Replies
0
Views
2K
AdminAdmin is verified member.
A
A
Replies
1
Views
3K
AdminAdmin is verified member.
A
Back
Top