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

mohani57395378

27-08-2019

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.

Answers (4)

Answers (4)

Himanshu_Singhal

MVP

29-08-2019

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.

mohani57395378

28-08-2019

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

Nirmal_Jose

MVP

27-08-2019

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>