[Zope] Accessing list elements

Thomas B. Passin tpassin@mitretek.org
Thu, 24 Jan 2002 11:26:42 -0500


[Smith, Neil]

> Is there a way of accessing a specific element from a list within a dtml
> method.  I have tried multiple formats of syntax that I thought might
work,
> but I can't find the right one.  I have got something working by using a
> dtml-in with a start and end set to the same value, but surely there is a
> better way.
>

It's just basic Python syntax for lists.  In Python, if you have a variable
called list, you get the 2nd element in the list by

    list[1]

(The indexing is zero-based).

In Zope,  with a Zope variable again called list, you can get its 2nd
element using

<dtml-var "list[1]">

In other dtml expression, you refer to the element the same way.

Cheers,

Tom P