[Zope] ZPT newbie Q

Tim tim@xxvii.net
Thu, 6 Mar 2003 02:47:06 -0500


G. wrote on Wednesday, March 5, 2003, 10:38:58 PM:
> I'd like to generate a list of links that does not include the index_html
> page.

Notice the tal:condition="python:item.getId()<>'index_html'" below.
Also notice the general use of object/title_or_id instead of just
object/title.

> My second question is: Is there any way to sort the list that's generated?

Sort is a bit awkward inside page templates. The sort part of this
code is basically ripped from the API reference in the Zope Book.
It does an insensitive sort on the title, then date.

  <font size=+1 tal:content="template/title_or_id">Title</font>
  <UL tal:condition="container/objectValues"
      tal:define="objects here/objectValues;
                  sort_on python:(('title', 'nocase', 'asc'),
                                  ('bobobase_modification_time', 'cmp', 'desc'));
                  sorted_objects python:sequence.sort(objects, sort_on)">
    <LI tal:repeat="item sorted_objects">
          <span tal:define="i item/title_or_id" 
                tal:condition="python:item.getId()<>'index_html'" 
                tal:replace="i">ITEM</span>
    </LI>
  </UL>

If you're wanting to do anything very complicated with lists, i'd just
write a python script to generate the list the way you want it, then
loop over that.

-- 
Tim Middleton | Cain Gang Ltd | "Who is Ungit?" said he, still holding
x@veX.net     | www.Vex.Net   | my hands. --C.S.Lewis (TWHF)
1