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

Get List of Child Pages in User Macro

MarkC
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.
December 8, 2015

I have the need to get a list of child pages under a parent page. However, I only want to pull in this data in a User Macro. I want to format it differently, and I can do that, but I can't seem to get the child pages to pull in. Help?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Stephen Deutsch
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.
December 9, 2015

Hi Mark,

It depends what you mean by child pages.  According to Confluence, there are two types of sub-pages:

Children: the pages that are directly ONE LEVEL under a page

Descendants: ALL pages that are under a page

For example:

My Page
    Child page 1
    Child page 2
          Descendant page 1
          Descendant page 2

So if you want to get children, use $content.getChildren(), and if you want to get all descendants, use $content.getDescendents() for Confluence versions earlier than 5.5, and $content.getDescendants() for newer versions.

MarkC
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.
December 9, 2015

And by child pages, I did mean 1 level down. Not descendants.

MarkC
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.
December 10, 2015

How do you go about getting the title and URL for each of the children?

MarkC
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.
December 10, 2015

Ignore the above. Got that working. But I can't get the children for a specific page. $content.getChildren(PAGEID) doesn't work, it seems.

MarkC
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.
December 10, 2015

I got this to work if I put the numbers directly into the $parampageId, but if I rely on the macro to pass that page ID into the string, it doesn't work. $pageManager.getPage($parampageId).getChildren()

Stephen Deutsch
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.
December 10, 2015

getPage requires a long for the ID, so I usually do something like this: #set ( $Long = $generalUtil.getSystemStartupTime() ) #set ( $pageId = $Long.parseLong($parampageId) ) #set ( $children = $pageManager.getPage($pageId).getChildren() )

MarkC
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.
December 10, 2015

One last question: Is there a way for the children to be sorted based on their position within the hierarchy? For example, the page tree shows this order: B A C. I want the children to show from this macro in the order of the hierarchy. The order of getChildren() seems to display them in some random order. Is there a way to get the hierarchy order?

MarkC
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.
December 10, 2015

Never mind. getSortedChild() does the hierarchy order. I'm still confused as to the ordering of getChild()

0 votes
Alex Yasurek
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.
December 8, 2015

Hey,

I found this other question someone posted and was answered that may help you:

https://answers.atlassian.com/questions/39360

TAGS
AUG Leaders

Atlassian Community Events