Expand my Community achievements bar.

SOLVED

Children Sorted page with number

Avatar

Level 2

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 

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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.

View solution in original post

5 Replies

Avatar

Employee Advisor

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 

Avatar

Community Advisor

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.

Avatar

Community Advisor

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

Avatar

Correct answer by
Employee Advisor

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.

Avatar

Community Advisor

Agree with @Jörg_Hoh 

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

 

For children traversing use resource traversing.



Arun Patidar