Stand with Ukraine 🇺🇦

Show All Pages with a Specific Label

Show Pages List for Label - Display a list of Confluence pages with a CSV download feature - Preview 2
Show Pages List for Label - Display a list of Confluence pages with a CSV download feature - Preview 3
confluence-content

This Confluence user macro calls the Confluence REST API to fetch pages a label using CQL. The result is rendered as a AUI-styled list with a header and CSV download button.

Try for free

Template

## Specify a label name parameter
#set($label = $parameters["label"])

#if(!$label)
<div class="aui-message aui-message-info">
    Please provide a <code>label</code> parameter.
</div>
#else

## Fetch pages for a specific label
#set($response = $ConfluenceManager.get("/wiki/rest/api/content/search?cql=type=page AND label='$label'"))
#set($results = $response.results)
#set($base = $response._links.base)

<div id="label-header" data-label="$!label" style="display:flex; align-items:center; gap:12px; margin-bottom:8px;">
    <div>
        <span class="aui-lozenge aui-lozenge-subtle aui-lozenge-inprogress">Showing pages for label:</span> <span class="aui-lozenge aui-lozenge-subtle aui-lozenge-new">$!label</span>
    </div>

    <button title="Download CSV" id="download-csv-btn"
        type="button"
        aria-label="Download CSV"
        style="
        display:inline-flex;
        align-items:center;
        gap:8px;
        border:0;
        border-radius:4px;
        padding:6px 12px;
        cursor:pointer;
        font-family:inherit;
        font-size:14px;
        ">
        <span class="iconify" data-icon="ph:download" data-inline="false" style="font-size:18px;"></span>
    </button>
</div>

## Create a list of pages
#if($response)
<ul id="label-pages-list" style="padding-left:18px;">
    #foreach($page in $results)
    #set($title = $page.title)
    #set($webui = $page._links.webui)
    #set($href = "${base}$webui")
    <li data-title="$!title" style="list-style-type: circle;"><a href="$!href" target="_blank" rel="noopener noreferrer">$!title</a></li>
    #end
</ul>
#else
<div>
    No pages found for label <code>$!label</code>.
</div>
#end

<script type="module">
    (function () {
        const btn = document.getElementById('download-csv-btn');
        const list = document.getElementById('label-pages-list');
        const header = document.getElementById('label-header');
        if (!btn) return;

        const label = (header && header.dataset && header.dataset.label) ? header.dataset.label: 'pages';
        const safeFilename = (name) => String(name).replace(/\s+/g, '_') + '-pages.csv';


        const escapeCsvField = (s) => {
            if (s == null) return '';
            s = String(s);

            if (/[",\r\n]/.test(s)) {
                return '"' + s.replace(/"/g, '""') + '"';
            }

            return s;
        };

        const buildCsv = () => {
            const rows = [];
            rows.push(['Title', 'URL'].map(escapeCsvField).join(','));
            if (!list) return rows.join('\r\n');

            for (const li of list.querySelectorAll('li')) {
                const a = li.querySelector('a');
                const title = li.getAttribute('data-title') || (a ? a.textContent.trim(): '');
                const url = a ? a.href: '';
                rows.push([title, url].map(escapeCsvField).join(','));
            }
            return rows.join('\r\n');
        };

        const downloadBlob = (content, filename) => {
            const blob = new Blob([content], {
                type: 'text/csv;charset=utf-8;'
            });
            if (navigator.msSaveBlob) {
                navigator.msSaveBlob(blob, filename);
                return;
            }
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.setAttribute('download', filename);
            a.style.display = 'none';
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
        };

        btn.addEventListener('click', (e) => {
            e.preventDefault();
            const csv = buildCsv();
            const filename = safeFilename(label);
            downloadBlob(csv, filename);
        });
    })();
</script>

<script>
    if (!window.iconifyOnLoad) {
        (function() {
            const s = document.createElement('script');
            s.src = 'https://code.iconify.design/2/2.2.1/iconify.min.js';
            s.defer = true;
            document.head.appendChild(s);
            window.iconifyOnLoad = true;
        })();
    }
</script>

#end

User Parameters

Label

Enter a label name to show pages for

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