[Zope] ZCatalog counting?

Rik Hoekstra rik.hoekstra@inghist.nl
Tue, 27 Jun 2000 22:53:01 +0200


>
>On Tue, 27 Jun 2000, Alexander Limi wrote:
>
>> Is there an easy way to count the number of occurences of a certain meta
>> type in a Catalog? E.g: I want a dtml snippet that outputs:
>
>Couldn't you do:
>
><dtml-call "REQUEST.set('counter', 0)">
>
><dtml-in "objectValues('DTML Document')">
>  <dtml-call "REQUEST.set('counter', counter+1)">
></dtml-in>
>
>This folder (<dtml-var title_or_id) has <dtml-var counter>
>number of objects with the meta type DTML Document.


um, not to be nitpicking, but if you'd want to know the number of objects
with a certain meta-type in a folder, the following is a bit shorter and
saves you an iteration:

 <untested>

<dtml-call "REQUEST.set('counter', _.len(objectValues(['DTML Document'])">
This folder (<dtml-var title_or_id) has <dtml-var counter>
 number of objects with the meta type DTML Document.

<dtml-let counter="_.len(objectValues(['DTML Document'])">
   This folder (<dtml-var title_or_id) has <dtml-var counter>
   number of objects with the meta type DTML Document.
</dtml-let>

</untested> not entirely sure of the dtml-let syntax, but you get the idea

Rik