xF2 Template Modification Customising the layout with custom user fields

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,497
Points
523

Reputation:

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:

1617009116100.png


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

1617009133300.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

1617009148400.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.
 

sarvin_pakzad

программист и дизайнер
Collaborate
Registered
Joined
Nov 14, 2020
Messages
46
Points
18

Reputation:

Good tutorial, thanks. can you tell me how to can that users can change the own "color hue setting" ?
 
Top