Confluence User Macro - Execute search query

Hello everybody,

is it possible to perform a search query in the background within a confluence user macro?

I want to display the found results in a bullet list at the confluence page. I have found some classes within the confluence SDK but i dont know how to get them working within velocity.

Example classe which could perform a search:

Have you got any ideas?

Thanks in advance!


1 answer

1 accepted

3 votes
Answer accepted

Instead of trying to mess with all that, why not just piggyback on top of one of the existing macros?

This should work for generating a CQL query:

## @noparams
$action.getHelper().renderConfluenceMacro('{contentbylabel:showLabels=false|showSpace=false|cql=type = "page" and <rest of cql>}')

This displays more or less a bulleted list (with a page icon instead of bullets. If you want to modify the results, just assign the results to a variable and directly modify the text with the text manipulation methods available to velocity (for example, to not show anything when there are no results instead of the no labels found panel).

Hello Stephen,

thanks for your reply!

That´s a great idea and is working fine.

One problem: I am searching for a name which can be found within an attachment. Content By Label is returning then something like this:

"Page Link" > "Link to attachment"

I have tried with string functions to just return the "Page Link" but this is not working fine. I have tried .split() and substring in combination with indexOf without any success. With the .split() function i only get returned an address of the string object:

2017-07-10 09_18_47-Link auf OrgChart Test - Michael Ruderer - ONE - confluence.png

This is normally an array and i don´t know how to get the value within velocitiy not the object address...

Have you got any ideas?

Best Regards,


Hi Michael,

Actually, what you get returned is a list of strings. Unfortunately velocity (at least the version that is included in Confluence) doesn't have very good list functions, so you're pretty much limited to #foreach ($listItem in $list). Here is something fairly simple that should work:


## @noparams
#set ( $htmlString = $action.getHelper().renderConfluenceMacro('{contentbylabel:showLabels=false|showSpace=false|cql=type = "attachment"}') )
#foreach ( $htmlTag in $htmlString.split(' <') )
  #set ( $htmlTag = '<' + $htmlTag )
  #if ( $htmlTag.contains('/download/attachments/') )
#end #end </ul>


Hi Stephen,

thanks that´s exactly what i needed!

Thank you very much!

Best Regards,



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,014 views 2 13
Read article

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