[Zope] Page Template tal:replace advice

Geir Bækholt Geir Bækholt
Mon, 14 Jul 2003 21:31:53 +0200


On  Mon, 14 Jul 2003 19:35:00 +0100 GMT (..20:35 where i live(GMT+2) )
Norman Khine asked the Zope mailinglist about the following:
  
> Hello,
> I am trying to generate some static pages from a database, I have
> created my template file, but I am have a small problem!

> The database has a field image, this contains the image filename, but
> some records don't have images at all, so my question is how to
> design my template so that if there is an image file, to display it,
> if not then not to display any image. Is this possible?

> This way we won't get any broken pages that don't show an image.

> So if I have this template, how can I include the <img
> tal:replace="structure images/35.gif | nothing"/>

say the database record is defined as "dbrec", and the image-field is
called "imgfield".

The following code will break if you have image-names defined in your db
that does not exist in theZODB, but ought to handle empty ones:

<untested code>

<img tal:define="imgname dbrec/imgfield | nothing"
     tal:condition="imgname"
     tal:replace="structure here/?imgname" />
    
</untested code>
:)

--
Geir Bækholt