[Zope] RE: Syntax for dtml-in property check?

Dylan Reinhardt zope at dylanreinhardt.com
Fri Aug 15 16:12:14 EDT 2003


On Thu, 2003-08-14 at 23:30, Dan Shafer wrote:

> Unfortunately, either I still don't get it or I'm doing something else
> wrong. My new code snippet looks like this:
> 
> 
> <<dtml-in expr="objectValues('Folder')" prefix=seq sort=title_or_id>
> 
> <<dtml-var seq_coach_id><<br>
> 
> 
> Now I get a key error on seq_coach_id.


That's because you don't have any object called seq_coach_id.  

As you iterate over your collection, the alias for each object will be
seq_item.  To check each seq_item for a particular property, try this:

<dtml-in "objectValues('Folder')" prefix=seq sort>
     <dtml-if "seq_item.get('coach_id') == 'whatever'">
          Do something
     </dtml-if>
</dtml-in>


The get() isn't strictly necessary... you could use seq_item.coach_id
but get() keeps you from throwing an exception if one of the objects
you're scanning over doesn't have the coach_id property.

> I appreciate the help more than I can say, by the way. This
> syntactical soup is very trying, esp. when someone comes up with a
> solution like this that I couldn't have found in a million years as
> far as I can tell! Without this list, I'd have bailed on Zope a year
> ago!


Zope can seem pretty arbitrary, particularly if you don't have a
background in Python, the language Zope is written in (and modeled on). 
Python is well worth spending some time with... a reasonably experienced
programmer can pick up about 80% of what there is to know in an
afternoon.  Programming newbies may take a few days.

http://python.org/doc/current/tut/

Also, the online help is pretty good once you get the feel for it.  That
"Help" link in the upper right of most Zope management screens yields
some useful information.  For details on how dtml-in works, search for
"in".

HTH,

Dylan





More information about the Zope mailing list