Skip to main content
mohani57395378
New Participant
Aug 27, 2019 9:28 PM UTC
Solved

Page.listChildren() or data-sly-list=currentPage.listChildren to return sorted list

Hi All,

I am recursively listing out all the sub pages from a path using data-sly-list=currentPage.listChildren. But its returning the list as per node structure, is there anyway we can pass some parameters to get a sorted list based on title or published date.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
rampai
rampaiAccepted solution
Level 1
Aug 30, 2019 4:26 AM UTC

Hi mohani57395378​,

Please check this as well.

Best Way to Sort a List of Resources ?

Regards,

Ram

5 replies

rampai
rampaiAccepted solution
Level 1
Aug 30, 2019 4:26 AM UTC

Hi mohani57395378​,

Please check this as well.

Best Way to Sort a List of Resources ?

Regards,

Ram

Translate
arunpatidar
New Participant
Aug 29, 2019 1:26 PM UTC

There is another method, which allows you to add filter while listing page

Page ("The Adobe AEM Quickstart and Web Application.")

You need to create filter by implementing below interface and there you can set cafeteria for a page to be included in list.

PageFilter ("The Adobe AEM Quickstart and Web Application.")

Translate
Arun Patidar
Himanshu_Singhal
New Participant
Aug 29, 2019 12:12 PM UTC

Using the Use script, there's no such method/parameter available to return sorted data. if you wish to get sorted list based on specific parameter/condition, in that case, write logic in Java. Write either in Sling model or service and utilise accordingly.

Translate
mohani57395378
New Participant
Aug 28, 2019 1:55 PM UTC

Hi Nirmala,

Thanks for your reply.

I have tried to do the same using currentPage.listChildren but i don't see any  methods which will give a sorted list based on some attributes(replication date, title) just like Filters(which will return specific pages).

use(function () {
     return { pageList : currentPage.listChildren }
});

Translate
Nirmal_Jose
Employee
Aug 27, 2019 9:40 PM UTC

data-sly-list is not currently having control to handle iteration order of list. You would have to change the order in the data you are feeding to list using JavaScript or Java Use API, following is example of JavaScript use API

In logic.js file

use(function () { 
     var someArrayVar = [1,2,3,4];
     return{ someArrayRev : someArrayVar.sort() };
});

In HTML Markup

<div data-sly-use.logic="logic.js"> 
     <div data-sly-list="${logic.someArrayRev}"> ${item} </div>
<div>
Translate