Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,312
Community Members
 
Community Events
168
Community Groups

How can I create a Confluence user macro that displays the full Confluence page path?

We have Confluence Server 6.9.1

1 answer

1 accepted

1 vote
Answer accepted

What do you mean by that? The page the macro is on? A page selected in the macro properties?

Yes, the page the macro is on.  Thank you for reading my post.

This will put the url on the page wherever you put the macro.

Macro Name:
page_url

Macro Title:
Page URL

Macro Body Processing:
No macro body

Template:

## @noparams

$settingsManager.getGlobalSettings().getBaseUrl()$content.getUrlPath()

Thank you Davin.  We want the macro to put the path in Confluence not the url, e.g.: Parent Page Title/Child Page Title/Child Page Title...

Ah, got it. This should work.

Macro Name:
path_to_page

Macro Title:
Path to Page

Macro Body Processing:
No macro body

Template:

## @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
Like # people like this

Works.  Thank you!  Is there a way to insert this path in the global footer, so we do it only once for all pages.

If you want to do it on a space by space basis you can go to Space tools -> Look and Feel -> Sidebar, header and footer you can put in wiki markup in the foot like such ...

{path_to_page}

Or if you want to do it on a global basis in Confluence Admin -> Look and Feel -> Layouts you can put the macro in the Page Layout decorator and it will show up on every page. FYI, this methods also can work on a space by space basis it is just a bit more complex than the above option. It is in Space tools -> Look and Feel -> Layout. Layout changes made in the space layout will override global layout changes.

Look for  ...

        <div id="main-content" class="wiki-content">
           $body
        </div>

And change it to ...

        <div id="main-content" class="wiki-content">
           $body
           $helper.renderConfluenceMacro("{path_to_page}")
        </div>
Like Gerardo Rigo likes this

Very useful.  Thanks!

Dear @Davin Studer ,

Thank you a lot for the example!

If I understand right this macro provides breadcrumb only for created page.

Don't you know, is it possible to modify this macro to insert such path for linked article on Confluence. For example I create a new page on Confluence and want insert link (currenly there are three options: Display URL, Display as link, Display as card). So I think of which will allow to insert link and Display it as path (breadcrumb).

as example (let's say it is a confluence article) which I want refer to: https://support.atlassian.com/confluence-cloud/docs/insert-links-and-anchors/
And it would be great to get the following path in newly created article with path to another article "Insert links":

Thank you in advance!

Dear @Davin Studer 

I did not know, that macro is available only for stand alone version of Confluence. And I looked for such possibility but for Cloud version.

So I am sorry for disturbing you.

Best wishes,

Mykhailo.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events