cancel
Showing results for 
Search instead for 
Did you mean: 

ftl Sorting

jbarrett
Champ in-the-making
Champ in-the-making
I have a template that lists out children of a certain type. 

<#list space.childrenByXPath[".//*[subtypeOf('msi:event')]"] as child>

Is there a way to order the results.  I need to order the results by a custom property in the display. 

Could there be a way to do it with a Lucene query?

Thanks

Josh
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
Yes you can sort using the FreeMarker built-in:

<#list space.childrenByXPath[".//*[subtypeOf('msi:event')]"]?sort_by(['properties', 'msi:myproperty']) as child>

Replacing 'msi:myproperty' with your custom property name.

Thanks,

Kevin

kevinr
Star Contributor
Star Contributor
I should also mention that sorting is possible using our Lucene integration - but it is not exposed in the FreeMarker API yet.

Thanks,

Kevin

jbarrett
Champ in-the-making
Champ in-the-making
Thanks!  Works great!

How would I reverse these results?

Thanks,

Josh

mikef
Champ in-the-making
Champ in-the-making
Use ?reverse e.g.

<#list space.childrenByXPath[".//*[subtypeOf('msi:event')]"]?sort_by(['properties', 'msi:myproperty'])?reverse as child>

Regards

Mike