Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Retrieving list of users in group macro

Hi there,

I'm new to Confluence but I'm starting to get a hang of it.

Right now I have a page on a space that is for our team. I have a section where I am putting "profile picture" macros to show each member of the group.

I was wonder how I could make a macro that would loop through the members of a group and call that macro, given a group name to look at.

So here is the psuedocode:

param1 = <PASSED IN PARAM>

foreach member in param1

{

profile_picture(member)

}

So the macro would take in the group name, loop thorugh the members, and call the "profile picture" macro for each member.

I know there is a "user list" macro, but it does not have exactly what I am looking for.

Any help would be greatly appreciated.

Thank you.

2 answers

1 accepted

Try this user macro:

## Users Pictures for Group - Confluence User Macro
##
##   Produces a pile of user profile pictures for members of a specific group
##
## WARNING:
##
##   Use very sparingly as this *will* slow down large Confluence instances.
##   Yes, it will try to print out 100,000 users if you have that many in the group
##
##   I generally remove this user macro after using once and add only when needed.
##   Or enable it for admins only.
##
## @param Group:title=Group Name|type=string|required=true|desc=The group name (yes, really)

  
#set($containerManagerClass = $action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null, null))
#set($containerContext = $containerManager.containerContext)
  
#set($userAccessor = $containerManager.containerContext.getComponent('userAccessor'))
#set($groupManager = $containerManager.containerContext.getComponent("groupManager"))
#set($group = $groupManager.getGroup($paramGroup))
#set($users = $userAccessor.getMemberNamesAsList($group) ) 

#foreach( $username in $users )

  #set($confluenceUser = $userAccessor.getUserByName($username))
  <ac:structured-macro ac:name="profile-picture">
<ac:parameter ac:name="User">
<ri:user ri:userkey="$confluenceUser.key" >
</ac:parameter&gt;&lt;/ac:structured-macro> #end

It should produce a pile of user profile pictures for members of a specific group.

Works exactly how I wanted it to. Thanks!

P.S. I understand the concern for the large sized groups. For a group like mine, it will not be as bad since we are a group of > 10 people. If you passed in something like "confluence-users" and you had a lot of people using Confluence, it might get hairy then.

In any event, thanks so much.

Hey @Kyle Crowley,

This was copied wholesale from here:
http://davidsimpson.me/2014/04/24/list-users-atlassian-confluence-user-macro/

The comments came through too.

Like InfoSec likes this

Works exactly how I wanted it to. Thanks!

P.S. I understand the concern for the large sized groups. For a group like mine, it will not be as bad since we are a group of > 10 people. If you passed in something like "confluence-users" and you had a lot of people using Confluence, it might get hairy then.

In any event, thanks so much.

@David at David Simpson AppsHas something changed in the years between that this macro is not longer working. I would really appreciate if you can guide, as this macro is going to add so much value to our confluence. Thanks for all your efforts.

Like Kmmaughs likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

Confluence Mythbusters: Does Atlassian even use Confluence?

Hi, Confluence collaborators! As part of #Confluence-Collaboratory month, we’ve created a very special Mythsbusters segment, where we're dive into an interesting myth and uncover the truth behind i...

1,481 views 7 29
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you