The macro fetches comments (inline and footer) from a selected Confluence page, counts likes, sorts by popularity and date, and displays the top N comments. Defaults to the current page if no specific page is set. It supports nested comments and provides clickable links to the original comment.
#set($allComments = [])
#set($topCount = $parameters.topCount)
#if(!$topCount || $topCount < 1)
#set($topCount = 3)
#end
## Default to the current page ID
#set($selectedPageId = $page.id)
## Check if a user parameter for page ID is set
#if($parameters.pageId)
## Parse parameters for spaceId and pageTitle
#if($parameters.pageId.contains(":"))
#set($paramParts = $parameters.pageIdentifier.split(":"))
#set($spaceId = $paramParts[0])
#set($pageTitle = $paramParts[1])
#else
#set($spaceId = $space.key)
#set($pageTitle = $parameters.pageIdentifier)
#end
## Fetch page ID using the Confluence REST API
#set($pageSearchResponse = $ConfluenceManager.get("/wiki/rest/api/content?title=$pageTitle&spaceKey=$spaceId"))
#if($pageSearchResponse)
#set($selectedPageId = $pageSearchResponse.results[0].id) ## Override the selected page ID
#end
#end
## Fetch inline comments for the selected page
#set($inlineCommentsResponse = $ConfluenceManager.get("/wiki/api/v2/pages/$selectedPageId/inline-comments"))
#if($inlineCommentsResponse)
#foreach($comment in $inlineCommentsResponse.results)
#if($comment.status == "current")
## Fetch like count
#set($likeCountResponse = $ConfluenceManager.get("/wiki/api/v2/inline-comments/$comment.id/likes/count"))
#set($likeCount = $likeCountResponse.count)
## Fetch comment text
#set($commentTextResponse = $ConfluenceManager.get("/wiki/api/v2/inline-comments/$comment.id?body-format=storage"))
#set($commentText = $commentTextResponse.body.storage.value)
## Add comment details to the list
#set($discard = $allComments.add({
"id": $comment.id,
"likeCount": $likeCount,
"commentText": $commentText,
"createdAt": $comment.version.createdAt,
"webuiLink": "$baseUrl$comment._links.webui"
}))
## Fetch and add child inline comments
#set($childrenResponse = $ConfluenceManager.get("/wiki/api/v2/inline-comments/$comment.id/children"))
#if($childrenResponse && $childrenResponse.results)
#foreach($childComment in $childrenResponse.results)
#if($childComment.status == "current")
## Fetch like count for the child comment
#set($childLikeCountResponse = $ConfluenceManager.get("/wiki/api/v2/inline-comments/$childComment.id/likes/count"))
#set($childLikeCount = $childLikeCountResponse.count)
## Fetch child comment text
#set($childTextResponse = $ConfluenceManager.get("/wiki/api/v2/inline-comments/$childComment.id?body-format=storage"))
#set($childCommentText = $childTextResponse.body.storage.value)
## Add child comment details to the list
#set($discard = $allComments.add({
"id": $childComment.id,
"likeCount": $childLikeCount,
"commentText": $childCommentText,
"createdAt": $childComment.version.createdAt,
"webuiLink": "$baseUrl$childComment._links.webui"
}))
#end
#end
#end
#end
#end
#end
## Fetch footer comments for the selected page
#set($footerCommentsResponse = $ConfluenceManager.get("/wiki/api/v2/pages/$selectedPageId/footer-comments"))
#if($footerCommentsResponse)
#foreach($comment in $footerCommentsResponse.results)
#if($comment.status == "current")
## Fetch like count
#set($likeCountResponse = $ConfluenceManager.get("/wiki/api/v2/footer-comments/$comment.id/likes/count"))
#set($likeCount = $likeCountResponse.count)
## Fetch comment text
#set($commentTextResponse = $ConfluenceManager.get("/wiki/api/v2/footer-comments/$comment.id?body-format=storage"))
#set($commentText = $commentTextResponse.body.storage.value)
## Add comment details to the list
#set($discard = $allComments.add({
"id": $comment.id,
"likeCount": $likeCount,
"commentText": $commentText,
"createdAt": $comment.version.createdAt,
"webuiLink": "$baseUrl$comment._links.webui"
}))
## Fetch and add child footer comments
#set($childrenResponse = $ConfluenceManager.get("/wiki/api/v2/footer-comments/$comment.id/children"))
#if($childrenResponse)
#foreach($childComment in $childrenResponse.results)
#if($childComment.status == "current")
## Fetch like count for the child comment
#set($childLikeCountResponse = $ConfluenceManager.get("/wiki/api/v2/footer-comments/$childComment.id/likes/count"))
#set($childLikeCount = $childLikeCountResponse.count)
## Fetch child comment text
#set($childTextResponse = $ConfluenceManager.get("/wiki/api/v2/footer-comments/$childComment.id?body-format=storage"))
#set($childCommentText = $childTextResponse.body.storage.value)
## Add child comment details to the list
#set($discard = $allComments.add({
"id": $childComment.id,
"likeCount": $childLikeCount,
"commentText": $childCommentText,
"createdAt": $childComment.version.createdAt,
"webuiLink": "$baseUrl$childComment._links.webui"
}))
#end
#end
#end
#end
#end
#end
## Sort comments by like count (descending) and then by creation date (descending)
#set($sortedComments = $SortTool.sort($allComments, ["likeCount:desc", "createdAt:desc"]))
#if(!$sortedComments || $sortedComments.size() == 0)
<p>
No comments available to display
</p>
#else
#if($sortedComments.size() < $topCount)
#set ($topCount = $sortedComments.size())
#end
<ol>
#foreach($comment in $sortedComments.subList(0, $topCount))
<li>
<a href="$comment.webuiLink" target="_blank" style="display: inline-block;">
<span>$comment.commentText</span>
</a>
<span class="aui-badge aui-badge-primary">$comment.likeCount</span>
</li>
#end
</ol>
#endPerform customized searches based on labels, content types, and other parameters.
Generate a list of all the content created by a current user by default or a specified user across your Confluence site.
Shows all attachments from the current space in a table view
Displays a list of pages in specific space with certain title or label
Display a custom list of recently updated content
Display Jira issue comments in a table
Parses a table containing cost and currency columns, converts each row's value into a selected result currency, and appends a footer row showing the total sum. Useful for tracking multi-currency expenses and reporting totals in a unified currency.
Display a list of Confluence pages with CSV download feature
The content of this macro will not go to the printing page
Shows H1 headings directly to children's topics for easy navigation.