Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Lavesh Budhrani
Contributor
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
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Contributor
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!

Matthew Beda
Contributor
February 26, 2025

Expanding upon Previous post to add in clickable links and dynamic toggle for long breadcrumb path. Added in Styling and JQuery to help with view and toggle functionality

## Macro Name: breadcrumbles
## Macro Title: BreadCrumbles
## Description: Creates Breadcrumb for current page
## Category: Administration
## Macro Body Processing: No Macro Body

##Template: ----begin code

## @noparams

#set($breadcrumbsAsHtml ='')
#set($currentPageID = $content.id)
#getBreadcrumbs($content.id)

<div class='BreadCrumbles'>$breadcrumbsAsHtml</div>

##recursive macro to get the path to page breadcrumbs

#macro( getBreadcrumbs $contentID )

    #set($thePage = $pageManager.getPage($contentID))
## ID comparison catch to avoid clickable link for current page and add in toggle element
        #if($contentID == $currentPageID)
            #set($breadcrumbsAsHtml = "<span class='BCtoggle' title='Click to View Full Breadcrumb Path'>...</span><span style='bold'>" + $thePage.getTitle() + "</span>" + $breadcrumbsAsHtml )
        #else
## Create clickable link for all Parent pages
            #set($breadcrumbsAsHtml = "<a href='"+$thePage.getUrlPath()+"'>" + $thePage.getTitle()+ "</a>" + $breadcrumbsAsHtml )
        #end

    ## Does this iteration have a parent?
    #if($thePage.getParent())
        #set($breadcrumbsAsHtml = $breadcrumbsAsHtml)

        ## Get parent of this iteration
        #getBreadcrumbs($thePage.getParent().getContentId().asLong())
    #end
#end

<style>
.BreadCrumbles a:not(:first-child) {display:none;}
.BreadCrumbles a {position:relative}
.BreadCrumbles a:after {
    content:' \\ ';
}
.BreadCrumbles .BCtoggle {
    font-size: 22px;
    font-weight: bold;
    line-height: 6px;
    padding: 0px 4px;
    background: #fff;
    display: inline-block;
    vertical-align: middle;
    height: 18px;
    border-radius: 6px;
    margin: 0 6px;
    border: 2px solid #ccc;
    cursor:pointer;
    transition:all .3s ease-in-out;
}
.BreadCrumbles .BCtoggle:hover{
    background:#e0e0e0;
}
.BreadCrumbles .BCtoggle.closeBC {
    line-height: 16px;
    font-family: monospace;
}
</style>
<script>

    AJS.toInit(function(){

        AJS.$('.BreadCrumbles .BCtoggle').click(function(){
            AJS.$('.BreadCrumbles a:not(:first-child)').toggle();
            AJS.$(this).text(AJS.$(this).text() == '...' ? ' < ' : '...');
            AJS.$(this).toggleClass('closeBC');
        });
    });

</script>

##Template: ----End code
Like • Nicolas Casel likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
atlassian, dance, gamification, badge, razzle dazzle, team '25 anaheim

Earn a one-day badge today and do the Atlazzle Dazzle! 🕺

Today only! Share what you’re the most excited about for Team ‘25 or just dance out the beginning of a new quarter with us.

Comment the post
AUG Leaders

Atlassian Community Events