Show Labels for Space — Confluence Cloud Macro
The macro constructs a CQL query to retrieve labeled content and executes it. If results are found, it displays the labels as clickable links.
User Parameters
Space Key Param
Select a space
Exclude Label
Enter a label or comma-separated labels to be excluded
Template
#set($spaceKey = $parameters.spaceKey)
#if($spaceKey.equals("currentSpace()"))
#set($spaceKey = $space.key)
#end
#set($excludeLabelParam = "")
#if ($parameters.excludeLabel)
#set($excludeLabelParam = $parameters.excludeLabel)
#end
## Prepare exclude labels as a list
#set($excludeLabels = [])
#foreach($label in $StringUtils.split($excludeLabelParam, ","))
#set($discard = $excludeLabels.add($StringUtils.trim($label)))
#end
## CQL query to get all labeled content in the space
#set($cqlQuery = "type IN (page, blogpost, attachment) AND space='$spaceKey'")
## Apply exclude logic if there are labels to exclude
#if($excludeLabels)
#set($excludeCondition = "label='" + $StringUtils.join($excludeLabels, "' OR label='") + "'")
#set($cqlQuery = "$cqlQuery AND NOT ($excludeCondition)")
#end
## Execute the query and expand metadata labels
#set($labelResponse = $ConfluenceManager.get("/wiki/rest/api/content/search?cql=$cqlQuery&expand=metadata.labels"))
## Render all labels as clickable links
#if($labelResponse.results.size() > 0)
<ul>
<p style="margin-bottom: 10px;">
<span class="aui-lozenge aui-lozenge-subtle aui-lozenge-success">Search result:</span>
</p>
#foreach($content in $labelResponse.results)
#foreach($label in $content.metadata.labels.results)
<li style="list-style-type: circle; margin-left: 30px;">
<a href="$labelResponse._links.base$content._links.webui" target="_blank">$StringUtils.capitalize($label.name)</a>
</li>
#end
#end
</ul>
#else
<p>
No labels found in the specified space or based on the exclusion criteria
</p>
#endRecommended Macros
Display a list of Confluence pages with CSV download feature
Displays a list of pages in specific space with certain title or label
Display the top comments from a selected Confluence page or the current page by default.
Shows a mention of the user who created the current page. If it's a current user, mention blue. If it's another user, mention gray.
The content of this macro will not go to the printing page
Shows worklogs from the Jira issue
List out a table to display the assignee history for Issues by JQL. Shows the following information: Issue Key, Summary, and Assignee history
Perform text searches within pages, blog posts, and attachments.