[Zope] Re: RE: RE: Q: How can i check the existence of an image?
Ben Gustafson
cbg3@earthlink.net
Sun, 6 Jan 2002 12:27:00 -0500
Hi Andreas,
I can't tell from your code snippet why you need the .gif extension (I would
just upload the .gif as an object and not use the extension in the id) or
what theme_ is used for, but let me show you a code snippet I came up with
this morning for my personal site that uses <dtml-else> and a default image,
and might be applicable to your needs.
--
<dtml-if imgID>
<dtml-call "REQUEST.set('theImgID', imgID)">
<dtml-else>
<dtml-call "REQUEST.set('theImgID', default_imgID)">
</dtml-if>
<dtml-var "imgs[theImgID]">
--
imgID is passed in the query string. theImgID is not defined anywhere else
except in REQUEST.set(). I define default_imgID as a property on the parent
folder. This works both when there is no query string (and therefore no
imgID) and when there is a query string.
HTH,
--Ben
(BTW Andreas, the message I sent directly to your address got bounced by
your mail server because "We don't accept mail from spam-domains!/Wir
akzeptieren keine Mails von Spam-Domains!" Sorry, man. Only trying to help!
;)
> Hello Ben,
>
> thanks for your help. The code peace works only if an image is
> available. Otherwise it will result in an error:
> =20
> Zope Error
> Zope has encountered an error while publishing this resource.
> Error Type: KeyError
> Error Value: theme_c_auf_einen_blick.gif
>
> But i need the <dtml-else> case. If an image is not available, the code
> has to give back an default image.
>
> My Code:
> <dtml-let myTemp=id>
> <dtml-let MyID="'theme_'+myTemp+'.gif'">
> 'if an image is not available, this will result in an KeyError
> <dtml-if "images[MyID]">
> <dtml-var "images[MyID]">
> <dtml-else>
> <dtml-var "images['theme_']">
> </dtml-if>
> </dtml-let>
> </dtml-let>
>