Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
This widget could not be displayed.
TAGS
Community showcase
Published in Confluence

Confluence Mythbusters: Does Atlassian even use Confluence?

Hi, Confluence collaborators! As part of #Confluence-Collaboratory month, we’ve created a very special Mythsbusters segment, where we're dive into an interesting myth and uncover the truth behind i...

231 views 2 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you