Forums

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

Child Page Count from Specific Parent Page by ID

becki.marsh December 12, 2023

I have the ability to count child pages of the current page via the code below. I'd now like to amend the code so that I can specify a specific page to count from.

#set($pageCount=0)

#foreach ($child in $content.children)
#set($pageCount = $pageCount + 1)
#end

$pageCount


 

1 answer

0 votes
Aron Gombas _Midori_
Community Champion
December 12, 2023

As user macros can use a bunch of Velocity context objects including those in the default Velocity context, you should have access to the `pageManager`.

Reference: https://docs.atlassian.com/ConfluenceServer/javadoc/8.7.1/com/atlassian/confluence/pages/PageManager.html

Using that, something like would work:

#set($pageCount=0)

#set($parentPage = $pageManager.getPage(123)) ## 123 is the ID of the specific page
#foreach ($child in $parentPage.children)
#set($pageCount = $pageCount + 1)
#end

$pageCount

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events