How to retrieve path of subpages | Community
Skip to main content
Level 2
March 18, 2021
Solved

How to retrieve path of subpages

  • March 18, 2021
  • 2 replies
  • 917 views

Hi All,

String [ ] parentpagepath;

Suppose parentpagepath[0] = /content/project/page1

 parentpagepath[1] = /content/project/page2

 

If page1 has subpages subpage1 and subpage2

page2 has subpages subpage3 and subpage4, how to iterate over parent path to retrieve path of the subpages?

 

Thanks in advance.

@1709464 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anudeep_Garnepudi

@helen_dd 

Get the PageManager (can get using @ScriptVariable in SlingModel or adapt ResourceResolver) and try below code.

for (String eachPage : parentpagepath) { Page page = pageManager.getPage(eachPage); Iterator<Page> childPages = page.listChildren(); while (childPages.hasNext()) { Page eachChildPage = childPages.next(); } }

 

2 replies

Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
March 18, 2021

@helen_dd 

Get the PageManager (can get using @ScriptVariable in SlingModel or adapt ResourceResolver) and try below code.

for (String eachPage : parentpagepath) { Page page = pageManager.getPage(eachPage); Iterator<Page> childPages = page.listChildren(); while (childPages.hasNext()) { Page eachChildPage = childPages.next(); } }

 

AG
Umesh_Thakur
Community Advisor
Community Advisor
March 18, 2021

Just get the currentPage and from there you can take a resource and iterate the listChildren of the resource that is pretty easy and convenient to use.

 Wherever is possible always try to use Sling API instead of JCR API.