Re: [Zope] random object with properties
Kevin Worth writes:
I'm trying to find/write a method that will choose a random image from a folder (easy, using the random how-to) But I also want to display the caption for the image, which is a property of that image.
This method:
<dtml-var expr="_.whrandom.choice(objectValues('Photo'))"> <dtml-if caption><dtml-var caption></dtml-if>
presents me with a random photo, but no caption. <dtml-let photo="_.whrandom.choice(objectValues('Photo'))"> <dtml-var photo> <dtml-with photo> <dtml-if caption>....</dtml-if> </dtml-with>
Dieter
At 11:21 PM +0100 11/21/00, Dieter Maurer wrote:
Kevin Worth writes:
I'm trying to find/write a method that will choose a random image from a folder (easy, using the random how-to) But I also want to display the caption for the image, which is a property of that image.
This method:
<dtml-var expr="_.whrandom.choice(objectValues('Photo'))"> <dtml-if caption><dtml-var caption></dtml-if>
presents me with a random photo, but no caption. <dtml-let photo="_.whrandom.choice(objectValues('Photo'))"> <dtml-var photo> <dtml-with photo> <dtml-if caption>....</dtml-if> </dtml-with>
This does not work with a "Photo" from the ZPhoto product. Anyone know why? It grabs the caption from the folder containing the Photo (which I created for testing this) If I use the standard "Image" it works beautifully, and should work for my purposes. -- ----------------------------------------------- Kevin Worth <kworth@engin.umich.edu> Computer Systems Specialist II and Adjunct Lecturer Department of Materials Science and Engineering University of Michigan
Kevin Worth writes:
<dtml-let photo="_.whrandom.choice(objectValues('Photo'))"> <dtml-var photo> <dtml-with photo> <dtml-if caption>....</dtml-if> </dtml-with>
This does not work with a "Photo" from the ZPhoto product. Anyone know why? It grabs the caption from the folder containing the Photo (which I created for testing this) If I use the standard "Image" it works beautifully, and should work for my purposes. Are you sure "ZPhoto" photos have a caption attribute/method? And you are allowed to access them?
If so, they would behave really strange. The "dtml-with" wraps the photo into an "InstanceDict" and pushes it onto the namespace stack. This means, that it is first asked for the "caption" object. Only if it says "Sorry" the next object on the namespace stack is asked. This is your folder. Dieter
participants (2)
-
Dieter Maurer -
Kevin Worth