Getting list length for single element in "dtml-in" loop
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* *
[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
participants (2)
-
cgreen -
Thomas B. Passin