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
BedrockMission!

Learn More

View all

Sign in to view all badges

How to retrieve path of subpages

Avatar

Avatar
Validate 1
Level 1
Helen_DD
Level 1

Likes

0 likes

Total Posts

6 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Applaud 5
View profile

Avatar
Validate 1
Level 1
Helen_DD
Level 1

Likes

0 likes

Total Posts

6 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Applaud 5
View profile
Helen_DD
Level 1

18-03-2021

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 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

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

 

Answers (1)

Answers (1)

Avatar

Avatar
Validate 1
MVP
Umesh_Thakur
MVP

Likes

147 likes

Total Posts

157 posts

Correct Reply

53 solutions
Top badges earned
Validate 1
Applaud 25
Ignite 3
Ignite 1
Give Back 5
View profile

Avatar
Validate 1
MVP
Umesh_Thakur
MVP

Likes

147 likes

Total Posts

157 posts

Correct Reply

53 solutions
Top badges earned
Validate 1
Applaud 25
Ignite 3
Ignite 1
Give Back 5
View profile
Umesh_Thakur
MVP

18-03-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.