cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker sorting on nested properties

ajshaw
Champ in-the-making
Champ in-the-making
Hey guys, quick question.

I have a template which displays documents in the current space.
I'd like these documents sorted by a custom property, 'order_number';

I can access the property to be displayed like this: ${child.properties["smSmiley Surprisedrder_number"]}


Can anyone tell me how i would sort by this property? the template is listed below.


<table>
   <tr>
      <td> </td>
      <td><b>Name</b></td>
      <td><b>Size</b></td>
      <td><b>Locked</b></td>
      <td><b> </b></td>

   </tr>
   <#list space.children?sort_by(['properties', 'smSmiley Surprisedrder_number'])   as child>
      <#if child.isDocument>
         <tr>
            <td><a href="/alfresco${child.url}" target="new"><img src="/alfresco${child.icon16}" border=0></a></td>
            <td><a href="/alfresco${child.url}" target="new">${child.properties.name}</a></td>
            <td>${(child.size / 1000)?string("0.##")} KB</td>
            <td> <#if child.isLocked>Yes</#if></td>
            <td>&nbsp${child.properties["smSmiley Surprisedrder_number"]}</td>
            <td><a href="/alfresco/command/script/execute/workspace/SpacesStore/0547b677-f3ef-11da-9322-e9cbf7c0ff45/workspace/SpacesStore/${child.properties["sys:node-uuid"]}?url=${space.url}
">Execute Script</a></td>
         </tr>
      </#if>
   </#list>
</table>



Thanks Smiley Happy
7 REPLIES 7

ajshaw
Champ in-the-making
Champ in-the-making
I'm posting this for the benefit of anyone who may be searching the forums with the same problem (i see a couple of old threads asking the same question).


It seems all that was wrong was that i needed to use "s rather than 's.

The following works fine :

<#list theList?sort_by(["properties","smSmiley Surprisedrder_number"]) as child>

tfpadilla
Champ in-the-making
Champ in-the-making
Thanks a lot.
I was almost getting crazy with this till I found your post.

trelofysikos
Champ in-the-making
Champ in-the-making
hello,

this post was very helpfull!

Is there any way the user could sort the items in my  FTL template ? e.g. by clicking the row title

thanks

trelofysikos
Champ in-the-making
Champ in-the-making
I found here
http://wiki.alfresco.com/wiki/Template_Guide#Default_Model

that i could get params from the url like this

<#assign keys = args?keys>
<#list keys as arg>     
   ${arg}
</#list> 

and thought i could get a param about sorting and pass it into Freemarker sort using
<#list theList?sort_by([${arg}]) as child>

But the get args isn't working for me ? any ideas why that is ?

trelofysikos
Champ in-the-making
Champ in-the-making
another question.. is there a way to sort in a descending order?

jarrett
Champ in-the-making
Champ in-the-making
?reverse would sort in descending order

krups
Champ in-the-making
Champ in-the-making
Thank you.
It helped me.