Display User Group on Profile Page

Permalink
Hi all,
does anyone know how I could display the group(s) a User is in on his/her Profile Page?

[ I'm not a PHP wizard, but I know how to copy and paste ;-) ]

Thanx, Maureen

zeker
 
Shotster replied on at Permalink Reply
Shotster
Hi Maureen,

You'll need to modify the view template for the profile single page. Copy the following core file...

/concrete/single_pages/profile/view.php

...to the following location...

/single_pages/profile/view.php

...and then edit the copy to include the following PHP code:

$groups = $profile->getUserObject()->getUserGroups();
echo '<ul>';
foreach ($groups as $group) {
   echo '<li>'.htmlentities($group).'</li>';
}
echo '</ul>';

That should get you close to what you're after.


-Steve
rubencouto replied on at Permalink Reply
rubencouto
Hello!

On view.php this works fine.
On members.php I get this error:

Fatal error: Call to a member function getUserObject() on a non-object in /home2/conceptu/public_html/iebpv/single_pages/members.php on line 24

Any idea?
Thanks!
Shotster replied on at Permalink Reply
Shotster
> On members.php I get this error:

Of course, because the $profile variable is undefined in that context. Are you trying to get the groups for the user viewing the page - i.e. the website visitor - or for each user in the list that's displayed on that page?

-Steve
rubencouto replied on at Permalink Reply
rubencouto
Hello!

Both profiles and members list are only viewable to the administrators. I would like to display the groups each member belongs to, both on profile view (already done) and on members list page.
I don't know enough coding to sort this out. Is there a way to define the variable profile in the context of the members.php page?
mhawke replied on at Permalink Best Answer Reply
mhawke
Try just changing $profile to $user like this instead:

$groups = $user->getUserObject()->getUserGroups();
echo '<ul>';
foreach ($groups as $group) {
   echo '<li>'.htmlentities($group).'</li>';
}
echo '</ul>';


Make sure you put this inside the "foreach($users as $user) {" loop that starts at line 24
rubencouto replied on at Permalink Reply
rubencouto
Hello!

Mhawke, thank you so much! Works perfectly!

Thanks again!
mhawke replied on at Permalink Reply
mhawke
No problem, glad I could help.
Shotster replied on at Permalink Reply
Shotster
Yeah, in that case, what mhawke said.

:-)

-Steve