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?
Community moderators have prevented the ability to post new answers.
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.
And by child pages, I did mean 1 level down. Not descendants.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How do you go about getting the title and URL for each of the children?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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() )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Never mind. getSortedChild() does the hierarchy order. I'm still confused as to the ordering of getChild()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
I found this other question someone posted and was answered that may help you:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.