[Zope] RE: RE: Q: How can i check the existence of an image?

Andreas Pelzner AP@aixvision.com
Sat, 5 Jan 2002 19:56:18 +0100


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=3Did>
      <dtml-let MyID=3D"'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>

- Andreas

>=20
> Hello Andreas,
>=20
> This example assumes that the MyID variable gets filled=20
> somehow, such as
> from the query string or form:
>=20
> 	<dtml-if "imgs[MyID]">
> 		<dtml-var "imgs[MyID]">
> 	</dtml-if>
>=20
> Where "imgs" is the name of the folder in which the image objects are
> stored. You don't need to specify the extension in your Zope=20
> image object
> names, as Zope will figure out the content type when you=20
> upload the image.
> The <dtml-var> tag will write out the IMG tag, including the path,
> dimensions, etc., for you. If you want to add additional=20
> parameters to the
> IMG tag, use <dtml-var "imgs[MyID].tag(param=3D'myParam')"> .
>=20
> --Ben
>=20
> > How can I check the existence on an image file in my image folder. I
> > coded a workaround, but it doesn't fit my needs exactly:
> >
> > <dtml-let myTemp=3D3Did>=3D20
> >
> > 'Build the image file name
> >
> > <dtml-let MyID=3D3D"'theme_'+myTemp+'.gif'">=3D20
> >
> >  'loop over each image in the image folder
> >
> > <dtml-in expr=3D3D"images.objectValues('Image')">
> >
> > ' String find
> >
> > <dtml-if "_.string.find(id(),MyID) > -1">=3D20
> >
> > ' -> if there is a matching file print image in HTML
> > <img src=3D3D"/images/<dtml-var id>" width=3D3D"145"=20
> height=3D3D"129"> 'print =3D
> > image
> > in HTML
> >
> > </dtml-if>
> > </dtml-in>
> > </dtml-let>
> > </dtml-let>
> >
> > ...but I'm looking for something like this:
> >
> > 'check if true or not
> > <dtml-in expr=3D3D"images.<image_name>">=3D20
>=20