• 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?

Floren

Well-known member
#1
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. :)
 

Brogan

XenForo moderator
Staff member
#4
I must have misunderstood your question.

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

Floren

Well-known member
#7
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.
 

James

Well-known member
#8
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.
 

Brogan

XenForo moderator
Staff member
#10
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}">
 

Floren

Well-known member
#12
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'].
 

James

Well-known member
#13
Oh, sorry.
$bbuserinfo in vBulletin = $visitor in XenForo. You will use {$visitor.is_admin} and {$visitor.is_moderator} instead of the $user equivalent.
 

Floren

Well-known member
#15
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;
}