Output child folders in a specifc order?
I'm using this script from the examples folder: <div tal:define="subfolders python:container.content.objectValues ('Folder')"> <ul tal:condition="subfolders"> <li tal:repeat="folder subfolders"> <a href="folder" tal:attributes="href folder/absolute_url" tal:content="folder/title">folder id</a> </li> </ul> <p tal:condition="not:subfolders"><b>There are no sub-folders here.</b></p> </div> It looks in my content folder and outputs links to all folders in there. The links come through as some random order, I want to be able to control this order, not alpha, but a defined order: I have 5 folders, I want to be able to tell it which ones to output 1st, 2nd, etc >> This will then form my navigation.
----- Original Message ----- From: <JBeard@porternovelli.com> To: <zope@zope.org> Sent: Tuesday, October 01, 2002 5:48 PM Subject: [Zope] Output child folders in a specifc order? [...]
It looks in my content folder and outputs links to all folders in there. The links come through as some random order, I want to be able to control this order, not alpha, but a defined order: I have 5 folders, I want to be able to tell it which ones to output 1st, 2nd, etc >> This will then form my navigation.
Hmm, very topical for me. I needed this just last week and came up with the following script. No guarantees on efficiency, but it does what I want. Improvements gratefully accepted ######### obs = [] order_prefs = {'indoor':1, 'outdoor':2, 'pool':3, 'hlsm':4, 'classes':5, 'corporate':6, 'department':7} def order_sort(ob1, ob2): try: return cmp(order_prefs[ob1.getId()], order_prefs[ob2.getId()]) except KeyError: return 0 home = context.sport_root() # This is a custom script of mine that returns the root of my site for folder in home.objectValues(['Folder',]): if folder.hasProperty('inTopMenu'): obs.append(folder) obs.sort(order_sort) #put the sport site root object first obs.insert(0, home) return obs ######### cheers, tim
Lookup OrderedFolder. // m
participants (3)
-
JBeard@porternovelli.com -
Mark McEahern -
Tim Hicks