display multiple users from username parameter in macro

Hi,

I'm brand new to Confluence and to Velocity. I'm trying to design a macro that will allow our users to enter multiple usernames into a parameter box in a custom macro, which will subsequently display those names in list form. My problem is I can't get it to display more than one username without breaking the code. Here's what I've come up with so far:

## Macro title: Design Status
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: cheiberg
## Date created: 05/27/2015
## Installed by: cheiberg
 
## @param Creator:title=creators|type=username|required=true|multiple=true
## @param Lead:title=leads|type=username|required=false|multiple=true
## @param Reviewers:title=reviewers|type=username|required=false|multiple=true
## @param Drivers:title=drivers|type=username|required=false|multiple=true

<ul>
<li><strong>Creator(s):</strong> 
#if( $paramCreator )
    <ac:link><ri:user ri:username="$paramCreator" /></ac:link>
#end
<li><strong>Owner(s):</strong> 
#if( $paramLead )
    <ac:link><ri:user ri:username="$paramLead" /></ac:link>
#end
<li><strong>Reviewer(s):</strong> 
#if( $paramReviewers )
    <ac:link><ri:user ri:username="$paramReviewers" /></ac:link>
#end
<li><strong>Drivers(s):</strong> 
#if( $paramDrivers )
    <ac:link><ri:user ri:username="$paramDrivers" /></ac:link>
#end
</li>
</ul>

As is, if I enter multiple usernames into Creator, for example, I'll come up with something like this: ~cheibergwwilliamson. How can I get my code to recognize that there are multiple names in a parameter and display them correctly?

Any help on this topic would be wonderful.

Thank you!

3 answers

1 accepted

Hi,

you would have to split the string by space or similar. Something like that:

<ul>
#foreach($user in $paramCreator.split("[,]+"))
<li> <ac:link><ri:user ri:username="$user" /></ac:link></li>
#end
</ul>

Thanks, Lucas! This works! I thought it might #foreach but I didn't know how to do it. 

One more question: This fix works to display the username, but won't notify users by email or through the confluence interface when they are selected and added to the macro. Is there any reason a user wouldn't be notified? If so, how can I fix it? 


I've already made sure that "@" notifications are working elsewhere; both on the page and in comments. 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

374 views 20 10
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you