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

XF 1.2 Hide Username

Discussion in 'XenForo Questions and Support' started by Itworx4me, Nov 26, 2013.

  1. Itworx4me

    Itworx4me Well-Known Member

    I would like to hide the username to the Unregistered usergroup and replace it with custom user field. How do I go about this?

    Thanks,
    Itworx4me
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    Find:
    Code:
                <xen:username user="$user" itemprop="name" rich="true" />
    
    Surround it with a conditional:
    Code:
    <xen:if is="$visitor.user_id">
          <xen:username user="$user" itemprop="name" rich="true" />
    </xen:if>
    
    However, since you want to display something else, you'll want to add an else statement:
    Code:
    <xen:if is="$visitor.user_id">
          <xen:username user="$user" itemprop="name" rich="true" />
    <xen:else />
          <a href="#" class="username" itemprop="name">$user.customFields.x</a>
    </xen:if>
    Change x to the field ID. The above example is for message_user_info. You'll need to find all occurrences and update accordingly.
     
    Itworx4me and vfustar like this.
  3. vfustar

    vfustar Member

    Thank you
     
  4. Itworx4me

    Itworx4me Well-Known Member

    $user.customFields.x doesn't work. I tried $vistor.customFields.x and that doesn't work either. Any other suggestions?

    Thank,
    Itworx4me
     
  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    The last sentence of that quote explains it.
     
  6. Itworx4me

    Itworx4me Well-Known Member

    I changed $user.customFields.nick_name and this is what I get:

    xen1.PNG

    Code:
    <xen:if is="{$visitor.user_id}">
                                <xen:username user="$user" itemprop="name" rich="true" />
                                <xen:else />
                                <a !href="" class="username" itemprop="name">$user.customFields.nick_name</a>
                            </xen:if>
     
  7. Sheldon

    Sheldon Well-Known Member

    Code:
    <a !href="" class="username" itemprop="name">{$user.customFields.nick_name}/a>
     
    Itworx4me likes this.
  8. Itworx4me

    Itworx4me Well-Known Member

  9. Jeremy

    Jeremy XenForo Moderator Staff Member

    Whoops. I guess that's what I get for writing that code while talking with Brogan about his add-on. Nice catch @Sheldon.
     
  10. Sheldon

    Sheldon Well-Known Member

    Hah. I didn't do anything, really... I am just becoming well-versed on using customFields. haha.
     

Share This Page