How can I display the name of the resource group a user is from?
I have 2 resource groups and I would like to display the resource group name in their profile.
<div>
<label><strong>Username:</strong><label>[[+username]]
<label><strong>Email:</strong><label>[[+email]]
<label><strong>Member Status:</strong><label>[[+group]]
</div>
Everything works but the group tag.
Any ideas and thank you for your time.
Erm ... Users don't belong to Resource Groups. They belong to User Groups. Because they can belong to more than one User Group, no simple tag will display a Group for them.
Users can have a "Primary Group," but it's stored as a group ID rather than a name, so a custom snippet could display that as well.
This should do it for the current user:
$groupId = $modx->user->get('group');
$group = $modx->getObject('modUserGroup', $groupId);
$name = $group->get('name');
if (empty($name)) {
$name = 'No Primary Group';
}
$modx->setPlaceholder('group', $name);
If you're making a list of users with your own snippet, it would depend on the code.
[ed. note: BobRay last edited this post 10 years, 11 months ago.]
I think, it should be
$modx->setPlaceholder('group', $name);
Definitely. Thanks Bruno.
Fixed above.