Confluence Macro / Method giving total Child Page count for Parent

Gavin Fowler
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.
March 6, 2013

Hi

I've been hunting around looking for a Macro / Method that gives a single numerical total for the number of Child Pages for the current Parent.

The intent is to use this child page count number along side the {expand} macro and {children} macro to create a crude page header which works something like (wiki pseudocode):

There are {ChildPageCount} Child Pages,
{expand:Click here to see child pages...}
{children:depth=1|sort=title|excerpt=true}
{expand}

Does anyone have any suggestions?

Thanks!

3 answers

1 accepted

1 vote
Answer accepted
Matthew J. Horn
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.
March 6, 2013

You can get the number of children using the $content object (which, when rendered in a page is an instance of a Page object). This class defines a getChildren() method, which returns a List of child pages. List has a count() method which returns an int.

All that to say, do this in your macro:

$content.getChildren().size()

Simrat August 27, 2015

Thanks for this valuable input @Matthew J. Horn, but this is just getting the child pages to depth one, its not getting number of all the descendants. For example Page 1 has a child page 1a which further has a child page 1aa, then this code if used on Page 1 just gives number of children as one i.e. its counting the child 1a but not its child 1aa.

Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 28, 2018

@Simrathave  you  figured out  how to  solve  this riddle. to  further count  the  inner child pages not ?

0 votes
RianA
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.
March 6, 2013

Looks like this answers might help

0 votes
Mirek
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 2013

Hi Gavin,

Why creating a macro? When looking at the OOTB confluence page you have something that you want just above the comment section. It looks similar to what you want to achieve:

It could be expanded and collapsed and it is availabe on every page that have a child page

Best Regards,

Mirek

Gavin Fowler
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.
March 6, 2013

Thanks for the feedback Mirek - I was aware OOB feature, and you're right it's pretty much what I'm looking for *however* my user community would like to see this (or something very similar) at the top of the parent page. The use case is simple, it allows drill down into child pages without having to scroll to the bottom of the parent page first.

Nick January 5, 2016

Mirek, I've tried that using the Child Pages macro but the count never appears.

Gavin Fowler
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.
January 5, 2016

Here's the macro I created (used a lot of other peoples input - all credit goes to those that helped). Create a macro with the "no body" option selected. This count pages that matches the page "label" specified. {code} ## Macro title: Count Pages by Label Macro ## Macro has a body: N ## Body processing: No Macro Body ## Output: ## ## Developed by: Gavin Fowler ## Date created: 15/Oct/2013 ## Installed by: Gavin Fowler ## @param Space:title=Restrict to space|type=string|desc=Enter a space key to restrict label search. For all spaces use @all, if blank only the current space will be searched (space key is case sensitive) ## @param Label:title=Label|type=string|required=true|desc=label to count (if the label is is not found then a value of zero will be returned) #set( $labelManager = $action.LabelManager ) #set( $labRef = $labelManager.getLabel($paramLabel) ) #if (!$labRef) 0 #else #if (!$paramSpace) #set( $paramSpace = $space.getKey() ) #end #if ($paramSpace != "@all") #set( $pages = $labelManager.getContentInSpaceForLabel(0 , -1 , $paramSpace, $labRef) ) #else #set( $pages = $labelManager.getContentForLabel(0 , -1 , $labRef) ) #end $pages.getCount() #end {code}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events