Template conditional for user title?

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. :)
 
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.
 
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.
 
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}">
 
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'].
 
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;
}
 
Top Bottom