This Confluence Cloud macro generates a static, alphabetically sorted list of unique labels used on a chosen parent page and all of its descendant pages. It resolves the root page from the current page or a user-defined parameter, retrieves root labels via REST API v2, then collects child page labels using a paginated CQL ancestor search through REST API v1. All labels are deduplicated, sorted with SortTool, and rendered as a clickable browseable list linking to Confluence label search results.
## Resolve root page ID
#set($rootPageId = $page.id)
#if($parameters.pageID && $parameters.pageID != "")
#set($rootPageId = $parameters.pageID)
#end
## Set storage for unique labels
#set($allLabels = {})
## Get labels from root page
#set($labelEndpoint = "/wiki/api/v2/pages/${rootPageId}/labels?limit=250")
#set($continueRootLabels = true)
#foreach($x in [1..50])
#if($continueRootLabels)
#set($rootLabelResp = $ConfluenceManager.get($labelEndpoint))
#if($rootLabelResp && $rootLabelResp.results)
#foreach($lb in $rootLabelResp.results)
#if($lb.name && !$allLabels.containsKey($lb.name))
#set($discard = $allLabels.put($lb.name, true))
#end
#end
#end
#if($rootLabelResp && $rootLabelResp._links && $rootLabelResp._links.next && $rootLabelResp._links.next != "")
#set($labelEndpoint = $rootLabelResp._links.next)
#else
#set($continueRootLabels = false)
#end
#end
#end
## Get all descendant pages + their labels
#set($searchEndpoint = "/wiki/rest/api/content/search?cql=ancestor=${rootPageId} AND type=page&expand=metadata.labels&limit=100")
#set($continueSearch = true)
#foreach($i in [1..100])
#if($continueSearch)
#set($resp = $ConfluenceManager.get($searchEndpoint))
#if($resp && $resp.results && $resp.results.size() > 0)
#foreach($pg in $resp.results)
#if($pg.metadata && $pg.metadata.labels && $pg.metadata.labels.results)
#foreach($lb in $pg.metadata.labels.results)
#if($lb.name && !$allLabels.containsKey($lb.name))
#set($discard = $allLabels.put($lb.name, true))
#end
#end
#end
#end
#end
#if($resp && $resp._links && $resp._links.next && $resp._links.next != "")
#set($searchEndpoint = $resp._links.next)
#else
#set($continueSearch = false)
#end
#end
#end
## Handle empty state
#if($allLabels.size() == 0)
<div>No labels found in this page tree.</div>
#stop
#end
## Sort labels
#set($sortedLabels = [])
#foreach($k in $allLabels.keySet())
#set($discard = $sortedLabels.add($k))
#end
#set($sortedLabels = $SortTool.sort($sortedLabels))
## Render results
<div style="width:25%; border-top:1px solid var(--ds-text, black); margin-bottom:1rem;"></div>
<ul style="list-style-type: circle; padding-left:22px; margin-top:8px;">
#foreach($lbl in $sortedLabels)
<li style="margin-bottom:4px;">
<a href="$baseUrl/search?cql=label='${lbl}'" target="_blank">
$lbl
</a>
</li>
#end
</ul>Display a list of Confluence pages with CSV download feature
Retrieve and display labels from a specified space
Space Information macro by space Id
Show an expandable page tree for a selected parent page (defaults to the current page)
Displays a list of pages in specific space with certain title or label
Display information about how many users have access to each space
Use sticky previous/next buttons to navigate through your Confluence page tree in a linear reading order
Shows page creation date
Shows H1 headings directly to children's topics for easy navigation.
Filter Confluence groups based on a specified filter value and display the results in different formats.