Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

User Macro for counting Child Pages with Label

Brian Taylor
Contributor
September 24, 2018

I have a macro that use to work that owed allow to select a page and a label and return the number of child pages under that page.  but getting the following 

Under Active Project Status Reports there are $pageCount pages with the label status-report

Instead of the number being returned I get the variable $pageCount

not sure why the this happening - any help appreciated 

 

## @param ParentPage:title=Page|type=confluence-content|required=true|desc=Select a page for which to count the children 
## @param Label:title=label|type=string|required=true|desc=Specify a label to count #set($pageCount = 0)
#set ( $colonIndex = $paramParentPage.indexOf(":") )
#if ( $colonIndex == -1 )
#set ( $parentSpaceKey = $space.key )
#set ( $parentPageName = $paramParentPage )
#else
#set ( $parentSpaceKey = $paramParentPage.substring(0, $colonIndex) )
#set ( $parentPageNameIndex = $colonIndex + 1 )
#set ( $parentPageName = $paramParentPage.substring($parentPageNameIndex) )
#end
#set ( $parentPage = $pageManager.getPage($parentSpaceKey, $parentPageName) )
#foreach( $child in $parentPage.descendents )
#foreach( $childlabel in $child.labels )
#if($childlabel.name == $paramLabel )
#set($pageCount = $pageCount +1)
#end
#end
#end
<p>Under $parentPageName there are $pageCount pages with the label $paramLabel</p>

 

1 answer

0 votes
Bill Bailey
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.
September 25, 2018

If I understand your comment, you are only seeing the variable name being displayed. That would suggest that the following statement is never found to be true:

 #if($childlabel.name == $paramLabel ) 

I would suggest using a different method to get a list of child pages, so instead of:

#foreach( $child in $parentPage.descendents )

I would try:

#foreach( $child in $parentPage.getChildren() )

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events