Using Custom User Fields to customise the layout

Using Custom User Fields to customise the layout

Paul B

XenForo moderator
Staff member
Brogan submitted a new resource:

Using Custom User Fields to customise the layout - Allow your members to choose which content they want to see

This guide will explain how to allow your members to choose which elements they wish to see, enhancing their forum experience.

For an explanation of both features, see the following pages of the help manual:
https://xenforo.com/help/custom-user-fields/
https://xenforo.com/help/templates/


It is impossible to please all members all of the time as far as site design, layout, and functionality is concerned.
Sometimes it's not possible to please any of them any of the time.

Read more about this resource...
 
Code:
<xen:if is="!{$visitor.customFields.profileposts}">
How can we add another conditional to this, for example usergroup?
 
You can just use AND to combine conditional statements.

However, as presumably you want to limit it to 'premium' user groups, your users may question why the customisation isn't being applied, as it won't stop the field appearing on their account preferences page.
 
The goal is to show ads to everyone except premium members who also have checked 'hide ads' in their settings. :)
 
Yes, that will work but the checkbox will still be shown to non premium members.

It also seems odd that premium members would choose to show ads...
 
Yes, that will work but the checkbox will still be shown to non premium members.

It also seems odd that premium members would choose to show ads...
I know we have it that way in vb, the idea of non premium members seeing it is they will become interested in premium membership (we put these 'premium members only' links below added features). Some premium members actually want to see the sponsor ads to know about the bargains. However Adsense is always hidden for them and everyone over 300 posts.
 
Does this not work in the template ad_above_content ? I have used this code:

Code:
<xen:if is="!{xen:helper ismemberof, $visitor, 3, 5, 6, 7, 13, 15} AND !{$visitor.customFields.advertenties}">

It's always hiding now.
 
You can dump it in the template to see if it's available.
Code:
{xen:helper dump, $visitor.customFields.advertenties}

It should be as it's part of the $visitor array.
 
Does this not work in the template ad_above_content ? I have used this code:

Code:
<xen:if is="!{xen:helper ismemberof, $visitor, 3, 5, 6, 7, 13, 15} AND !{$visitor.customFields.advertenties}">

It's always hiding now.
For anyone interested, this is the working code:
Code:
<xen:if is="{xen:helper ismemberof, $visitor, 3, 5, 6, 7, 13, 15} AND {$visitor.customFields.hide_google_ads}">

*keep empty* (show no banner)

<xen:else />

*put Adsense code here* (show banner)

</xen:if>

This allows premium members/mods/admins etc to switch off banners or show them. Other user groups still see/can check the checkbox but it will not work until they upgraded their account.
 
hmm, I'm trying to give users an option for disabling or enabling margins on .pageWidth, but it seems to not be recognizing my custom field ID (in EXTRA.css)

Code:
<xen:if is="{$visitor.customFields.noMargins}">
    .pageWidth
    {
        margin: 0px 0%;
    }
</xen:if>

8vKbNGb.jpg


The option does appear in the preferences, but it's acting as if the custom field ID doesn't exist. Checking the option does nothing, and if I change the conditional to <xen:if is=!... it does what I expected it to do , but the actual preference checkbox continues to do nothing (it would then be stuck with the lack of margins regardless of what's selected.)
 
EXTRA.css doesn't support such conditional statements. You have to edit the relevant template directly.
 
Last edited:
EXTRA.css doesn't support conditional statements. You have to edit the relevant template directly per the instructions.

Odd, it says it I can use XenForo template syntax at the bottom. :( I'm not that great with CSS, do you know what template that would be? I already tried inserting it into PAGE_CONTAINER (I didn't see it in forum_list) under <div class="pageWidth"> but it doesn't do anything when placed there.

EDIT: Whoops, wrong place
 
Last edited:
I want to create a custom user field but i need to set the field in such a way that once user inputs a value and submit, another user on the website cannot input similar value.

For example, when user A inputs 'abcd@email.com' in the email field in the contact details, user B cannot use same 'abcd@email.com' in his email field.

Now, my question is that how do i create a custom field that work in this way
 
Top Bottom