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

Template conditional for user title?

Discussion in 'XenForo Questions and Support' started by Floren, Mar 24, 2011.

  1. Floren

    Floren Well-Known Member

    Hi,

    Is there a specific template conditional I could use, in order to enhance a user title?
    For example, I want to make the user title italic in postbit, if that user belongs to a specific secondary group.

    Thanks. :)
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    http://xenforo.com/help/user-groups/

    Just set the styling in the title field, HTML is supported.
     
  3. Floren

    Floren Well-Known Member

    Nah, is not what I wanted. :)
    This should do it:
    Code:
    <xen:if is="{xen:helper ismemberof, $user, 5}">
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    I must have misunderstood your question.

    Why are you using a conditional when the user title can be styled using HTML?
     
  5. James

    James Well-Known Member

    Possibly to override the display priority.
     
  6. Brogan

    Brogan XenForo Moderator Staff Member

    I presume the default title ladder is being used then, rather than a user title override.
     
  7. Floren

    Floren Well-Known Member

    Well, what I want to do is a little more complex... so I still need your help guys. :)
    I think it might require a plugin, after all. Basically, I want to perform this change:
    In each postbit, if the postbit user belongs to a specific secondary group AND if the user viewing the board is either an admin or moderator, add a star next to the userTitle. So the user title will look like:
    Active Member (any users viewing the thread)
    Active Member* (mods or admins viewing the thread)


    I never looked at the Xenforo code yet, so I'm totally newbie how the plugins work. :)
    Thanks for your help guys.
     
  8. James

    James Well-Known Member

    You should be able to do that with a template edit...

    Code:
    <xen:if is="{xen:helper ismemberof, $user, x} AND {$user.is_admin} OR {$user.is_moderator}">
    //code
    </xen:if>
    Replace x with the usergroup ID.
     
  9. Floren

    Floren Well-Known Member

    Thanks James. Can I use an array to define multiple usergroups?
    {xen:helper ismemberof, $user, array(1, 2 , 3)}
     
  10. Brogan

    Brogan XenForo Moderator Staff Member

    The usergroup helper doesn't support arrays.

    You need to use it like so:

    <xen:if is="!{xen:helper ismemberof, $visitor, 3} AND !{xen:helper ismemberof, $visitor, 4}">
     
  11. James

    James Well-Known Member

  12. Floren

    Floren Well-Known Member

    Thanks James. There is a small detail: I do not want to check if the postbit user is an admin, but rather if the current logged user has admin or mod priviledges.

    Your code checks if the postbit user belongs to usergroup x and the postbit user is an admin.
    I want to check if the postbit user belongs to usergroup x and I'm logged as an admin into forums. If that condition apply, the extra code will be displayed into template.

    In vBulletin we used to do that with $post['usergroupid'] and $bbuserinfo['variable'].
     
  13. James

    James Well-Known Member

    Oh, sorry.
    $bbuserinfo in vBulletin = $visitor in XenForo. You will use {$visitor.is_admin} and {$visitor.is_moderator} instead of the $user equivalent.
     
    Floren likes this.
  14. Floren

    Floren Well-Known Member

    Thanks James! I need to do the same thing for the online users template and the card... time to hunt those templates.
     
  15. Floren

    Floren Well-Known Member

    I ended up editing the php code as is a lot easier... instead of modifying several templates:

    Code:
    /**
     * Helper to get the user title for the specified user.
     *
     * @param array $user
     * @param boolean $allowCustomTitle Allows the user title to come from the custom title
     *
     * @return string
     */
    public static function helperUserTitle($user, $allowCustomTitle = true)
    {
    	if (!is_array($user) || !array_key_exists('display_style_group_id', $user))
    	{
    		return '';
    	}
    
    	if ($allowCustomTitle && !empty($user['custom_title']))
    	{
    		return htmlspecialchars(self::_clientTitle($user, $user['custom_title']));
    	}
    
    	if (empty($user['user_id']))
    	{
    		$user['display_style_group_id'] = XenForo_Model_User::$defaultGuestGroupId;
    	}
    
    	if (isset($user['display_style_group_id']) && isset(self::$_displayStyles[$user['display_style_group_id']]))
    	{
    		$style = self::$_displayStyles[$user['display_style_group_id']];
    		if ($style['user_title'] !== '')
    		{
    			return self::_clientTitle($user, $style['user_title']);
    		}
    	}
    
    	if (empty($user['user_id']) || !isset($user['trophy_points']))
    	{
    		return ''; // guest user title or nothing
    	}
    
    	foreach (self::$_userTitles AS $points => $title)
    	{
    		if ($user['trophy_points'] >= $points)
    		{
    			return self::_clientTitle($user, $title);
    		}
    	}
    
    	return '';
    }
    
    /**
     * Helper to determine if an user is a licensed user.
     *
     * @param array $user
     * @param string $title
     *
     * @return string
     */
    protected function _clientTitle(array $user, $title)
    {
    	if (in_array(7, explode(',', $user['secondary_group_ids'])))
    	{
    		$visitor = XenForo_Visitor::getInstance();
    		if ($visitor['is_admin'] || $visitor['is_moderator'])
    		{
    			return $title . '&#42;';
    		}
    	}
    
    	return $title;
    }
     
  16. gldtn

    gldtn Well-Known Member

Share This Page