1. 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?

Discussion in 'Troubleshooting and Problems' started by Luxus, Jun 3, 2012.

  1. Luxus

    Luxus Well-Known Member

    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?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    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 and Jake Bunce like this.
  3. Luxus

    Luxus Well-Known Member

    Thank you. That worked like a charm :)
     
    Yorick likes this.
  4. Luxus

    Luxus Well-Known Member

    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.
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    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'
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    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!
     
  7. Luxus

    Luxus Well-Known Member

    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?
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    The only way is to turn off custom titles.

    customtitleperms.PNG

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

    Luxus Well-Known Member

    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>
     
  10. Chris D

    Chris D XenForo Developer Staff Member

    How about promoting people into different user groups when they reach certain point numbers?
     
  11. Luxus

    Luxus Well-Known Member

    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.
     
  12. Luxus

    Luxus Well-Known Member

    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 :)
     
  13. Luxus

    Luxus Well-Known Member

    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.
     
    Crazy-Achmet and Chris D like this.
  14. Chris D

    Chris D XenForo Developer Staff Member

    Nice work!
     

Share This Page