[Zope] <dtml-if> question

Ivan Cornell ivan.cornell@framestore.co.uk
Thu, 22 Feb 2001 13:24:26 +0000


>
> What the following code should do is test wheter an image exists and
> if it exists render it in the browser. If it doesn't exist it should show an empty
> default image. I found two ways to do it and both do it wrong in different ways
>
>              <dtml-let foto="'/Cis/fotos/afoto.jpg'">
>
>              <dtml-if expr="_.getitem('foto')">
>              <img src="&dtml-foto;">
>              <dtml-else>
>              <img src="/Cis/fotos/Noface.jpg">
>              </dtml-if>

Try something like this:

<dtml-if "_.hasattr(this(), '/Cis/fotos/afoto.jpg')"><dtml-let
foto="/Cis/fotos/afoto.jpg"><dtml-var foto></dtml-let>
<dtml-else>
<img src="/Cis/fotos/Noface.jpg">
</dtml-if>

Also, note that you can't embed dtml inside dtml.

Ivan