How can I create a user macro that displays the breadcrumbs of the current page?

Lavesh Budhrani May 2, 2024

I would like to display the pages under which the current page is nested in a breadcrumbs format along with the link.

https://community.atlassian.com/t5/Confluence-questions/Can-we-link-to-a-confluence-page-using-the-path-of-that-page/qaq-p/1772485

This article was helpful to get the output but I would also need each of the pages in the breadcrumbs to have links.

Any suggestions?

Thanks in advance!

FYI, this is for Confluence Data Center version.

1 answer

0 votes
Laurie Sciutti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 2, 2024

Hello @Lavesh Budhrani ~ if this is for DC, you could create a user macro (as opposed to a paid Marketplace app).  User macros aren't available in Cloud.  Here's an old post that may help (I haven't tested this):  https://community.atlassian.com/t5/Answers-Developer-Questions/Add-breadcrumbs-to-a-page-with-a-user-macro/qaq-p/507751 

Lavesh Budhrani May 6, 2024

I was able to use the following user macro code that displays the breadcrumbs in such a format:

Page Level 1 / Page Level 2 / Page Level 3 / Current Page

 

## @noparams

#set($breadcrumbs = "")
#set($breadcrumbSeperator = " / ")

#getBreadcrumbs($content.id)

$breadcrumbs

##recursive macro to get the path to page breadcrumbs
#macro( getBreadcrumbs $contentID )
    #set($thePage = $pageManager.getPage($contentID))
    
    #set($breadcrumbs = $thePage.getTitle() + $breadcrumbs)
    
    ## Does this iteration have a parent?
    #if($thePage.getParent())
        #set($breadcrumbs = $breadcrumbSeperator + $breadcrumbs)
        
        ## Get parent of this iteration
        #getBreadcrumbs($thePage.getParent().getContentId().asLong())
    #end
#end

I would like to enhance this code to make the breadcrumbs clickable. Any help on this is greatly appreciated!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events