Forums

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

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

Gerardo Rigo November 12, 2018

We have Confluence Server 6.9.1

1 answer

1 accepted

1 vote
Answer accepted
Davin Studer
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.
November 12, 2018

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

Gerardo Rigo November 13, 2018

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

Davin Studer
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.
November 13, 2018

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()
Gerardo Rigo November 13, 2018

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...

Davin Studer
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.
November 13, 2018

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
Gerardo Rigo November 13, 2018

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

Davin Studer
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.
November 13, 2018

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
Gerardo Rigo November 14, 2018

Very useful.  Thanks!

mykhailo m August 13, 2021

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!

mykhailo m August 15, 2021

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
AUG Leaders

Atlassian Community Events