Skip to main content
Level 2
August 26, 2022
Solved

Children Sorted page with number

  • August 26, 2022
  • 5 replies
  • 1334 views

Hi All,

I have requirement to display the dynamic number of child page in one component.

Example: parent page -> 4 child page should be sorted on the basis we can assign number 

 

Page1,page2,page3 and page4

Now I have created one title component with page number and that page number need to display 

 

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 joerghoh

Don't use a query for this case, it's definitely easier to collect the direct (!) child pages via the API; a query will consider the complete subtree by default, that could even be grand-children.

5 replies

Mohit_KBansal
Adobe Employee
Adobe Employee
August 26, 2022

There are several ways to handle this, a few are

  1. Using Oak index - Add page number as index/sortable property in oak index. Now to list the child below the parent page, use a query with a sort parameter as the page number.
  2. In your sling model, simply iterate all children below the parent, and create an object list, then leverage Java Comparator [1] to perform sorting in the child object list.

 

[1] https://www.javatpoint.com/Comparator-interface-in-collection-framework 

HeenaMadan
Community Advisor
Community Advisor
August 26, 2022

Use indexing to sort page with its number. Add page number of the child pages as sortable indexed property in oak:index. Use a query with a sort parameter as the page number to list the child pages.

arunpatidar
Community Advisor
Community Advisor
August 26, 2022

you can simply use query to get sorted results

 

type=cq:Page 
path=/content/we-retail/us/en 
orderby.sort=desc 
orderby=@jcr:content/pageIndexNumber
p.limit=-1
Arun Patidar
joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
August 29, 2022

Don't use a query for this case, it's definitely easier to collect the direct (!) child pages via the API; a query will consider the complete subtree by default, that could even be grand-children.

arunpatidar
Community Advisor
Community Advisor
August 30, 2022

Agree with @joerghoh 

Don't use query until you are targeting huge tree or subtrees.

 

For children traversing use resource traversing.

Arun Patidar