Customising the layout with custom user fields

Customising the layout with custom user fields

Paul B

XenForo moderator
Staff member
Brogan submitted a new resource:

Customising the layout with custom user fields - Now you see it ...

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.

Read more about this resource...
 
Hi Brogan

I have created an html widget and let the members themselves choose whether they want to see it or not.
Thanks to your instructions, it was easy going.

I show the widget in the forums and in the thread overview.

1614868520246.webp

I want to hide the widget for guests. Can I combine different display conditions in one widget?

And if so, what is the display condition to hide a widget for guests?
 
Search forums use the same criteria as the batch update threads in acp. It's a public search display of the results.
 
The tutorial is great.

But i always have some difficulty to apply the conditional statements on XenForo, shame on me.

What i want to do is to give a permission, using the custom user fields, to the user choose to show/hide their postbit statistics to the public.

Is basically the contrary of the code in the display condition:

!$xf.visitor.Profile.custom_fields.removeStatistics

Any tips? And sorry for the trouble.

EDIT for testing: Something like that?

$xf.visitor.message-userExtras.custom_fields.isMemberOf(2).HidePostBit
 
Last edited:
You would need to edit the template and wrap the content you want hide/show with a conditional statement using the full <xf:if syntax.
 
You would need to edit the template and wrap the content you want hide/show with a conditional statement using the full <xf:if syntax.

Interesting. I was thinking that using the message-userExtras was enough as a wrap in the display condition.
 
I will have to do some experimenting with this in templates. I have some style modifications to make, where I want users to be able to customize the view themselves. This will come in handy, provided the !$xf.visitor.Profile.custom_fields variable is available in the templates I want to use. (I will have to dump the variables to find out.)
 
Is it possible to create a new account preferences page to hold these custom fields? For example, you could have a "Website Customization" page with a whole bunch of these custom fields listed. Can that be done without an add-on?
 
* bump *

I want to create a Custom User Field that is a multiple choice (either drop down selection or radio buttons). Assuming I create a field named graphs and have 3 choices and set the values from 0 to 2, what would the display condition need to be to target one of the specific values?

I plan to create 3 different widgets and each one would only display if the corresponding choice was made for graphs.
 
I figured it out. I used (for example):
Code:
$xf.visitor.user_id AND $xf.visitor.Profile.custom_fields.graphs==2

I assume that having $xf.visitor.user_id in there is superfluous when I'm testing for .graphs>0 but might be necessary when I'm testing for .graphs==0
 
Top Bottom