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

Get/display Page ID - Confluence Internal Code Edited

I am trying to display a page's ID within itself i.e. within the content of the page the page ID is displayed. 

Q/A within the community recommend using $content.getIdAsString() but that has not worked. I've tried to input this within a HTML macro and without one as well but to no avail. 

I'm trying to get the ID of the page so that an HTML code block could reference the page it is included on instead of inputting the page ID by hand every single time. 

Looking forward to your responses. 

1 answer

1 accepted

3 votes
Answer accepted

Hi,

you have to create a user macro with that content:

## Macro title: getpageid
## Macro has a body: N

## @noparams

$content.getIdAsString()

Then, put the macro to your page. 

If you need help, creating a user macro, have a look at this article

Hi Thomas, 

Thanks for the quick reply and much appreciated. I had a hunch (which I was ignoring) that this ought to be put in a macro. In turn, could this macro then be used within an HTML code block? 

Here is what my code block looks like right now:

<input type="image" src="/download/attachments/171705685/BackReturn.png" onclick="location.href=document.referrer; return false;"> 
<input type="image" src="/download/attachments/171705685/PDFdownload.png" onclick="location.href='/spaces/flyingpdf/pdfpageexport.action?pageId=171706153';">

The last pageID (underlined) is what I am trying to get through the code/macro (dynamically) so that it doesn't require manual input every single time. Could it be something like action?pageId=getpageid

Thomas Schlegel Community Leader Sep 07, 2017

No, you can't use that in an html code block natively. This macro simply returns the id as a string. 

But you could change the macro, so that it is not only displaying the id, but returning the whole html-input-tag.

I have to leave now, so I don't have the time to try that out.

I will look at this tomorrow, but maybe you can try it meanwhile on your own. It's not so hard ;-)

Sounds like a plan. I'll give it a try. 

Thanks again :)

Thomas Schlegel Community Leader Sep 08, 2017

did you get it on you own? 

If not, here's the content of the macro:

## @noparams

<input type="image" src="/download/attachments/171705685/BackReturn.png" onclick="location.href=document.referrer; return false;">
<input type="image" src="/download/attachments/171705685/PDFdownload.png" onclick="location.href='/spaces/flyingpdf/pdfpageexport.action?pageId=$content.getIdAsString()';">

Hi Thomas, 

Thanks for the wonderful initial suggestion. I was able to create a macro that dynamically got the pageID. However, initially I only created the macro with the code you provided but quickly realized that the HTML macro doesn't accept other macros within itself. 

Therefore, I included the entire HTML code (including the pageID) within the macro and everything works as intended. All my CSS and HTML elements are now where they should be and the icons onclick events work

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

Introducing Confluence Cloud and Jira Software Cloud Premium

Wherever you are in your team’s journey , our goal is to support your big ambitions. We’re a cloud-first company with the mission of unleashing the potential of every team, and to address the range ...

694 views 5 18
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