• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.1 if condition for custom profile fields?

Luxus

Well-known member
#1
I have made a custom profile field and need to <xen:if it. The ID of the field is "country". Now I am looking for a condition similar to this:


Code:
<xen:if customprofilefield="country">
bla bla
</xen:if>
Is this possible?
 

Chris D

XenForo developer
Staff member
#2
Luxus, you're looking for something like this:

Code:
<xen:if is="{$user.customFields.country}">
If the field has data this text will be shown
</xen:if>
or

Code:
<xen:if is="{$user.customFields.country} == 'United Kingdom'">
If the field contains 'United Kingdom' this text will be shown
</xen:if>
 

Luxus

Well-known member
#4
Another question. Is this above possible with user ranks/titles?
I tried

Code:
<xen:if is="{$userTitle.rookie}">bla bla</xen:if>
Code:
<xen:if is="{$user.userTitle.rookie}">bla bla</xen:if>
Code:
<xen:if is="{$user.userTitle} == 'rookie'">bla bla</xen:if>
but none of them is working.
 

Chris D

XenForo developer
Staff member
#5
Should be this:

Code:
<xen:if is="{xen:helper userTitle, $user} == 'rookie'">
YOU ARE A ROOKIE
</xen:if>
It is case sensitive so 'rookie' is different to 'Rookie'
 

Chris D

XenForo developer
Staff member
#6
It's worth adding:

As user titles are usually linked to usergroups, potentially another way of achieving this is:

Code:
<xen:if is="{xen:helper ismemberof, $visitor, 10}">
YOU ARE A ROOKIE
</xen:if>
Where 10 is the usergroup ID of people in the "rookie" group.

Even if that doesn't help, it's worth bearing in mind as it's useful!
 

Luxus

Well-known member
#7
Thank you :) The code is working, but I forgot a critical thing. All titles belong to the same group "Registered Users". By earning points users should get these user titles, but remain in the same group:
usertitles.png
I wanted to add images for each of those user titles by using conditions. The issue here is that if users can change their custom title, the user rank images will then be changed too. If the Newcomer group has 1 star as rank image and the Member group 3 stars, members can decrease their stars by changing their user title to Newcomer and thus, faking their ranks. How can I fix it?
 

Chris D

XenForo developer
Staff member
#8
The only way is to turn off custom titles.

customtitleperms.PNG

That will stop them from being able to change their title.
 

Luxus

Well-known member
#9
That will work, but I want to allow members to change their user titles.
Hm...does an condition exist for points?

Code:
<xen:if is="{xen:helper userPoints} == '50'">
user has the members rank</xen:if>
 

Chris D

XenForo developer
Staff member
#10
That will work, but I want to allow members to change their user titles.
Hm...does an condition exist for points?

Code:
<xen:if is="{xen:helper userPoints} == '50'">
user has the members rank</xen:if>
How about promoting people into different user groups when they reach certain point numbers?
 

Luxus

Well-known member
#11
That would work too and will probably be used by me if everything else fails. But I would like to keep every user in the same group if possible to save work. Also I believe a future version of XenForo will provide custom images for user ranks. Then it won't be necessary anymore to make usergroups for each rank.
 

Luxus

Well-known member
#12
Allright, I decided to distribute user rank images by trophy points. All I need now is the if condition that checks if a user has reached X points. I couldn't figure out the right code. Help is greatly appreciated :)
 

Luxus

Well-known member
#13
I have figured out the code.
Code:
<xen:if is="{$user.user_group_id} == 2 AND {$user.trophy_points} == 1"><p>user rank image</p></xen:if>
User Group 2 is for registered users. This prevents other special usergroups from getting rank images that are supposed to be for normal registered users only.
 

Chris D

XenForo developer
Staff member
#14
I have fugured out the code.
Code:
<xen:if is="{$user.user_group_id} == 2 AND {$user.trophy_points} == 1"><p>user rank image</p></xen:if>
User Group 2 is for registered users. This prevents other special usergroups from getting rank images that are supposed for normal registered users only.
Nice work!