[silva-dev] Order Attribute
eric casteleijn
eric at infrae.com
Tue Oct 10 18:31:53 CEST 2006
Timo Schuerg wrote:
> Hello!
>
> I build the navigation bar of our website by iterating over the Silva
> Publications in the Silva Root.
>
> <span tal:define="items python:root.silva.objectValues('Silva
> Publication')">
>
> What I would like to do is order this list according to the ordering you
> see in the Silva Management Screen, so that if you move something up and
> down there this is reflected in our navigation bar. This could look
> something like this:
>
> <span tal:define="items python:root.silva.objectValues('Silva
> Publication')"
> sorted_items python:sequence.sort( items, (('_____','cmp'),)
> )">
>
> My Problem is that I can't find out how to get at the information which
> position was assigned to a Silva Publication. I looked through all of
> the service_metadata, but I can't find anything.
>
> It would be very kind if you could give me a quick hint.
Hi Timo,
there is a method 'get_public_tree' which will give you a list of tuples
(depth, object) which can help you to build a nice navigation:
<ul tal:define="items python:here.get_public_tree()">
<li tal:repeat"item items" tal:content="item/1" tal:attributes="class
string:level-${item/0}"/>
</ul>
or somesuch, (I wouldn't use css classes in this way, but you can
imagine how to use the depth number to visualize the nesting.)
Note that this returns all published publishables (in the correct
order), not just the publications, but filtering on that shouldn't be a
problem. If you pass in a depth argument to get_public_tree you can
specify at which depth to stop.
There is also get_public_tree_all, which does basically the same, but
also shows content within contained publications, which the regular
get_public_tree does not.
hope this helps,
--
- eric casteleijn
http://infrae.com
More information about the silva-dev
mailing list