[Zope] showing images

Dieter Maurer dieter@handshake.de
Fri, 25 Oct 2002 21:28:08 +0200


Ebbe Kvist writes:
 > ...
 > a/ test if there is a thumbnail file for the idnumber variable and
You can use the following Python Script to check whether a folder
as a given child (which is the Id):

 hasChild:
   Parameters: folder,child
   Body:
      try:
        folder[child]
        return 1
      except KeyError:
        return 0   

 You use it in the form 
  
    hasChild(your_folder_containing_the_thumbnails,str(idnumber))

 (If you use it in "DTML", "str" becomes "_.str").

 > b/ if so - show it together with the metadata - and if not - show a dummy picture instead
 In DTML:
   <img src="<dtml-if expr="hasChild(...)"
                ><dtml-var expr="your_folder...[_.str(idnumber)].absolute_url()
		><dtml-else>dummy_picture_url</dtml-if>">

 In ZPT:
     <img src="dummy_picture_url"
       tal:define="idnumber python: str(idnumber)"
       tal:attributes="
         src python:here.hasChild(your_folder,idnumber) and your_folder[idnumber].absolute_url() or default;
	 "
     >


Dieter