This Confluence macro constructs a CQL query to retrieve labeled content and executes it. If results are found, it displays the labels as a table or a list with clickable links.
#set($spaceKey = $space.key)
#if($parameters.space && !$parameters.space.equals("currentSpace()"))
#set($spaceKey = $parameters.space)
#end
#set($viewMode = "table")
#if($parameters.viewMode && $parameters.viewMode != "")
#set($viewMode = $parameters.viewMode)
#end
#set($excludeList = [])
#if($parameters.excludeLabels && $parameters.excludeLabels != "")
#foreach($ex in $parameters.excludeLabels.split(","))
#set($discard = $excludeList.add($ex.trim()))
#end
#end
## Collect labels from actual content via CQL
#set($labels = {})
#set($cql = "type IN (page,blogpost,attachment) AND space='${spaceKey}'")
#set($s = 0)
#set($l = 200)
#set($go = true)
#foreach($i in [1..20])
#if($go)
#set($r = $ConfluenceManager.get("/wiki/rest/api/content/search?cql=${cql}&expand=metadata.labels&start=${s}&limit=${l}"))
#foreach($c in $r.results)
#foreach($lb in $c.metadata.labels.results)
#set($n = $lb.name)
#if(!$excludeList.contains($n))
#if($labels.containsKey($n))
#set($cur = $labels.get($n))
#set($cur = $cur + 1)
#set($discard = $labels.put($n, $cur))
#else
#set($discard = $labels.put($n, 1))
#end
#end
#end
#end
#if($r.results.size() < $l)#set($go = false)#else#set($s = $s + $l)
#end
#end
#end
## Early return if nothing found
#if($labels.size() == 0)
<div>
No labels found in this space π
</div>
#stop
#end
## Render as unordered list
#if($viewMode == "list")
<ul>
#foreach($n in $labels.keySet())
<li>
<a href="${baseUrl}/search?cql=label='${n}' AND space='${spaceKey}'">$n</a>
<span style="color: #707070; margin-left: 4px;">($labels.get($n))</span>
</li>
#end
</ul>
## Render as table (default)
#else
<table class="aui aui-table-sortable" style="width:50%;">
<thead>
<tr>
<th style="width: 50%; padding: 8px 12px;">Content count</th>
<th style="width: 50%; padding: 8px 12px;">Label</th>
</tr>
</thead>
<tbody>
#foreach($n in $labels.keySet())
<tr>
<td style="padding: 8px 12px; text-align:left;">$labels.get($n)</td>
<td style="padding: 8px 12px;">
<a href="${baseUrl}/search?cql=label='${n}' AND space='${spaceKey}'">$n</a>
</td>
</tr>
#end
</tbody>
</table>
#endDisplay a list of clickable labels for a specified page tree
Displays a list of pages in a specific space with a specified title or label
List all Confluence spaces with details such as space name, author, and creation date
Display Jira issue comments in a table
Display a personalized greeting message for a logged-in user
Display space details such as type, status, creation date, and links to permissions and calendars
Show all attachments from the current space in a sortable table view
Find images within page attachments. Handy for reusing files and updating them all at once.
Display a list of Confluence pages with a CSV download feature
Show H1 headings for child topics to enable easy navigation