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

cgreen cgreen@ttsg.com
Tue, 15 Jan 2002 14:16:09 -0500


--------------050702080601060403080602
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Wow -- this list has been so immensely helpful, it at once demonstrates 
how wonderful the open source
community is.... and what an idiot *I* am.

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:


    Zope Error
    
Zope has encountered an error while publishing this resource.

*Error Type: InError*
*Error Value: Strings are not allowed as input to the in tag*


??? So my list is interpreted as a string if it is only one element in 
length.

What is the simplest way to deal with the possibility of a one element 
(or *zero* element)
list being returned?? I tried   <dtml-if  expr="len(field_topic) < 2"> 
DO <dtml-elif expr="len(field_topic) >= 2"> DO
OTHER </dtml-if>.

It didn't work. The <dtml-in> loop still gets called, even though the if 
loop should never reach it. Unless I've
designed the loop incorrectly. I call upon those of you who actually 
understand the inner intracacies of Zope
for your help. And I thank you in advance. 

peace*
*


--------------050702080601060403080602
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html><head></head><body>Wow -- this list has been so immensely helpful, it at once demonstrates how wonderful the open source<br>
community is.... and what an idiot *I* am.<br>
<br>
I have a dtml script which receives a form variable "field_topic", which is a list of the topic property or <br>
properties of the document or documents within a folder, and performs actions based upon the values<br>
in this list. The code is thus:<br>
<br>
&lt;dtml-with REQUEST&gt;<br>
&lt;dtml-in field_topic&gt;<br>
&lt;dtml-let topik=sequence-item&gt;<br>
&lt;table border="1"&gt;<br>
 &nbsp;&nbsp; &nbsp; &nbsp; &lt;dtml-in expr="PARENTS[0].objectValues(['STX_Document'])" sort="topic,title"&gt;<br>
 &nbsp;&nbsp; &lt;dtml-if "topic == topik"&gt;<br>
........<br>
<br>
If there are two or more elements in "fileld_topic", all is well. However, if "field_topic" contains<br>
only one element, I get the following error message:
<h2>Zope Error</h2>
<p>Zope has encountered an error while publishing this resource.</p>
<p><strong>Error Type: InError</strong><br><strong>Error Value: Strings are not allowed as input to the in tag</strong></p>
<p><br>
??? So my list is interpreted as a string if it is only one element in length. </p>
<p>What is the simplest way to deal with the possibility of a one element (or *zero* element)<br>
list being returned?? I tried &nbsp; &lt;dtml-if&nbsp; expr="len(field_topic) &lt;
2"&gt; DO &lt;dtml-elif expr="len(field_topic) &gt;= 2"&gt; DO <br>
OTHER &lt;/dtml-if&gt;.</p>
<p>It didn't work. The &lt;dtml-in&gt; loop still gets called, even though the if loop should never reach it. Unless I've<br>
designed the loop incorrectly. I call upon those of you who actually understand the inner intracacies of Zope <br>
for your help. And I thank you in advance.&nbsp; </p>
<p>peace<strong><br>
</strong></p>
</body></html>
--------------050702080601060403080602--