[Zope] Getting list length for single element in "dtml-in" loop

Thomas B. Passin tpassin@mitretek.org
Tue, 15 Jan 2002 14:44:26 -0500


[cgreen]>
> I have a dtml script which receives a form variable "field_topic", which
> is a list of the topic property or
> properties of the document or documents within a folder, and performs
> actions based upon the values
> in this list. The code is thus:
>
> <dtml-with REQUEST>
> <dtml-in field_topic>
> <dtml-let topik=sequence-item>
> <table border="1">
>        <dtml-in expr="PARENTS[0].objectValues(['STX_Document'])"
> sort="topic,title">
>    <dtml-if "topic == topik">
> ........
>
> If there are two or more elements in "fileld_topic", all is well.
> However, if "field_topic" contains
> only one element, I get the following error message:
>

The reason you can't detect the non-list condition with your code is because
_.len(form_variable), the form_variable being a string, probably has a
length greater than 1.

The easiest way to deal with this is to rename the form element, by adding
":list" to its name.  This causes Zope to return a list even if there is
only one element.  Then you won't have a problem.

Cheers,

Tom P