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.
## 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>
#endDisplay a list of clickable labels for a specified page tree
Retrieve and display labels from a specified space
Displays a list of pages in a specific space with a specified title or label
Display space details such as type, status, creation date, and links to permissions and calendars
Show an expandable page tree for a selected parent page, defaulting to the current page
Generate an alphabetical list of labels from all spaces, linking each label to its corresponding content pages
Show H1 headings for child topics to enable easy navigation
Dynamically list all child pages of the current page in a table format
Filter Confluence groups based on a specified filter value and display the results in different formats
Display Confluence page edit and view restrictions to provide essential permission details, including users, groups, and inherited access