Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to retrieve path of subpages

Helen_DD
Level 2
Level 2

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.

@AEM 

1 Accepted Solution
Anudeep_Garnepudi
Correct answer by
Community Advisor
Community Advisor

@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();
	}
}

 

View solution in original post

2 Replies
Anudeep_Garnepudi
Correct answer by
Community Advisor
Community Advisor

@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();
	}
}

 

View solution in original post

Umesh_Thakur
Community Advisor
Community Advisor

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.