[Zope] help! dtml-if question
Jim Washington
jwashin@vt.edu
Wed, 04 Oct 2000 12:30:15 -0400
Hi, Anthony
how about:
<dtml-if "_.len(objectValues(['Blurb'])) > 0">
Your _.has_key() (I think you meant _.hasattr()) statement was looking
for something named "Blurb", not a thing of type"Blurb", so of course it
failed.
The objectValues(['atype']) statement returns a list of the things of
the type, so checking for a non-zero length of the list will do what
you need.
-- Jim Washington
Dr. Anthony Monta wrote:
> Hi,
>
> I've tried to find a solution myself but now am stuck. I created a
> little "Blurb" product for a university department website so that
> faculty members can announce recent publications on the department's
> homepage. They create these ZClass instances in their own folders,
> and a DTML method in the top-level folder grabs and displays them at
> random. (I want to avoid using ZCatalog for the time being.) What
> the method does is randomly choose a faculty folder, and then randomly
> choose a Blurb instance within that folder. Here's the hack I came up
> with:
>
> <dtml-with Dept>
> <dtml-with Fac>
> <dtml-with Sites>
> <dtml-with "_.whrandom.choice(objectValues(['Folder']))">
> <dtml-with "_.whrandom.choice(objectValues(['Blurb']))">
> <dtml-var index_html>
>
> (end tags omitted)
>
> The problem is that this method will produce an Index Error when it
> comes across a folder that doesn't contain an instance of "Blurb"
> class. So I need to make the selection of a folder conditional on
> Zope's finding a Blurb in that folder. Here's what I tried after
> reading up:
>
> <dtml-with Dept>
> <dtml-with Fac>
> <dtml-with Sites>
> <dtml-with "_.whrandom.choice(objectValues(['Folder']))">
> <dtml-if "_.has_key('Blurb')">
> <dtml-with "_.whrandom.choice(objectValues(['Blurb']))">
> <dtml-var index_html>
> </dtml-with>
> <dtml-else>
> Some default Blurb would appear.
>
> This method fails. Can someone help?
>