[Zope] Selecting which objects to loop over
Dieter Maurer
dieter@handshake.de
Tue, 17 Jun 2003 19:26:32 +0200
Rafael Cordones Marcos wrote at 2003-6-16 19:14 +0200:
> ...
> How do I filter objects in the <dtml-in> tag based on some object property?
>
> For instance, I want to loop over a set of objects in current directory, like,
> say all DTML Document objects that have an id (name) that begins with "tab-".
>
> I have tried with:
>
> <dtml-in expr="objectValues('DTML Document')">
> <dtml-if expr="_.string.find(id, 'tab-') == 0">
> <p>Object title: &dtml-title;</p>
> </dtml-if>
> </dtml-in>
>
> But I get a
>
> Error Type: AttributeError
> Error Value: namefind
"id" is a dangerous name. Sometimes, it is a string and
sometimes (in your case) it is a method.
Always use "getId" (which is a method).
Try:
<dtml-if expr="getId().startswith('tab-')">
...
</dtml-if>
Dieter