[Zope] dtml-if question

Dieter Maurer dieter@handshake.de
Thu, 3 Jan 2002 21:30:26 +0100


Stephan Goeldi writes:
 > I am pulling a list of names out of an SQL database to show their name=
 and=20
 > adress etc. In a specific zope folder are some pictures of SOME names.=
 If=20
 > there exists a picture for a certain name, it should be displayed. If =
not,=20
 > there should be a placeholder. What is the correct syntax of this?
 >=20
 > What I think of is something like this:
 >=20
 > <dtml-in dep_cc>
 > <LI><a href=3D"mailto:<dtml-var EMAIL>"><dtml-var NAME></a>
 >   <dtml-if LOGIN.jpg>
 >         <img src=3D"<dtml-var LOGIN>.jpg">
 >     <dtml-else>
 >       no picture!
 >   </dtml-if>
 > </dtml-in>
Seems to me that you have several distinct problems:

  *  checking whether an object has a specific content item

  *  the object id is not given as a constant but as an expression

For the first problem, there is no complete solution in
TTW code. You can use "aq_explicit" to approximate, but sometimes
it will give wrong results. You need a file system based Python
method to make it safe. Search for "aq_base" in the mailing list
archives.

For the second problem, you have the "getattr/hasattr" methods
(of =B4_=B4 or function in Python Scripts).

You can try:

    <dtml-if expr=3D"_.hasattr(your_specific_folder.aq_explicit, LOGIN+'.=
jpg'">
      <img ...>

By the way, your "img" tag will only work, when the images can be
accessed throuch acquisition. It will fail when there are in a subfolder.


Dieter