Stand with Ukraine 🇺🇦

A Space-Wide Picture of Your Labels

Show Labels for a Space - Retrieve and display labels from a specified space - Preview 2
Show Labels for a Space - Retrieve and display labels from a specified space - Preview 3
confluence-content

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.

Try for free

Template

#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>
#end

User Parameters

Space

Choose a space

View Mode

Choose how to display results

Exclude Labels

Enter a label or comma-separated labels to exclude

Chosen by Top Global Companies Across Diverse Industries

BNP Paribas
Census
CNES
EDP
HHMI
HP
Hyundai
Index
Intercars
Melia
BNP Paribas
Census
CNES
EDP
HHMI
HP
Hyundai
Index
Intercars
Melia
Ministry
NVIDIA
PayPay
Pfizer
Qualcomm
Rail Canada
Red Cross
SEC
Space Institute
Telefonica
Ministry
NVIDIA
PayPay
Pfizer
Qualcomm
Rail Canada
Red Cross
SEC
Space Institute
Telefonica

Got Questions?

Fill out the form, and we'll guide you through every step of the way