Plone: Reverse Folder Contents in TAL Define

Using TAL, I needed to display the folder contents with dates ascending (newest first). By default context/folderlistFolderContents returns the tuple descending.

So I fixed it by using a ternary statment hack, that evaluates both entries/blocks.



[code]
<metal:fill fill-slot="main">
<metal:main_macro define-macro="main"
tal:define="portal_type python:here.getPortalTypeName().lower().replace(' ', '_');
folder_list context/folderlistingFolderContents;

folder_list python: (folder_list.reverse(), folder_list)[1];

base_macros here/base/macros;
view_template python:'%s_view' % portal_type;
<!-- rest of code -->
[/code]

Comments

Anonymous said…
Great! Many thanks, that's what I was looking for! I used it as a draft for plone.comments reverse order :-)

Popular posts from this blog

Python SUDS with Windows Authentication (SOAP)

Text Sherlock the OpenGrok alternative (Source Code Search Engine)

How to remove, update, or replace the WKWebView inputAccessoryView