RE: RE: Q: How can i check the existence of an image?
Hello Ben, thanks for your help. The code peace works only if an image is available. Otherwise it will result in an error: 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> - Andreas
Hello Andreas,
This example assumes that the MyID variable gets filled somehow, such as from the query string or form:
<dtml-if "imgs[MyID]"> <dtml-var "imgs[MyID]"> </dtml-if>
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 image object names, as Zope will figure out the content type when you 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 parameters to the IMG tag, use <dtml-var "imgs[MyID].tag(param='myParam')"> .
--Ben
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=3Did>=20
'Build the image file name
<dtml-let MyID=3D"'theme_'+myTemp+'.gif'">=20
'loop over each image in the image folder
<dtml-in expr=3D"images.objectValues('Image')">
' String find
<dtml-if "_.string.find(id(),MyID) > -1">=20
' -> if there is a matching file print image in HTML <img src=3D"/images/<dtml-var id>" width=3D"145" height=3D"129"> 'print = 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=3D"images.<image_name>">=20
Andreas Pelzner schrieb:
Hello Ben,
thanks for your help. The code peace works only if an image is available. Otherwise it will result in an error:
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]">
try <dtml-if "hasattr(images, MyID)"> instead
<dtml-var "images[MyID]"> <dtml-else> <dtml-var "images['theme_']"> </dtml-if> </dtml-let> </dtml-let>
- Andreas
Hello Andreas,
This example assumes that the MyID variable gets filled somehow, such as from the query string or form:
<dtml-if "imgs[MyID]"> <dtml-var "imgs[MyID]"> </dtml-if>
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 image object names, as Zope will figure out the content type when you 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 parameters to the IMG tag, use <dtml-var "imgs[MyID].tag(param='myParam')"> .
--Ben
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=3Did>=20
'Build the image file name
<dtml-let MyID=3D"'theme_'+myTemp+'.gif'">=20
'loop over each image in the image folder
<dtml-in expr=3D"images.objectValues('Image')">
' String find
<dtml-if "_.string.find(id(),MyID) > -1">=20
' -> if there is a matching file print image in HTML <img src=3D"/images/<dtml-var id>" width=3D"145" height=3D"129"> 'print = 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=3D"images.<image_name>">=20
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
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]">
try <dtml-if "hasattr(images, MyID)"> instead I must correct this a little bit: <dtml-if "_.hasattr(images,MyID) ">
<dtml-var "images[MyID]"> <dtml-else> <dtml-var "images['theme_']"> </dtml-if> </dtml-let> </dtml-let>
participants (2)
-
Andreas Pelzner -
Dirk Datzert