Page Template tal:replace advice
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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"/> <html> <head> <title tal:content="template/title">The title</title> </head> <body> <img src="35.gif" border="0" tal:define="im container/35.gif" tal:attributes="src im/absolute_url; width im/width; height im/height; alt im/title" /> </body> </html> Thanks Norman zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zz/********/z/****\zzz|****\*\zz|*******|z z/^^^^^^^^/z/******\zz|*^^^^|*|z|*|^^^^^|z norman khine zzzzzz/**/z|**/^^\**|z|*|zzz|*|z|*|zzzzzzz mailto:norman@khine.net zzzzz/**/zz|*|zzzz|*|z|****/*/zz|*****|zzz purley z/******/zz|*|zzzz|*|z|*|^^zzzzz|*|^^^|zzz UK zzZ/**/zzzz|**\^^/**|z|*|zzzzzzz|*|zzzzzzz zz/******/zz\******/zz|*|zzzzzzz|*|*****|z z/^^^^^^/zzzz\^^^^/zzz|^|zzzzzzz|^^^^^^^|z zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz -----BEGIN PGP SIGNATURE----- Version: PGP 7.0.4 iQA/AwUBPxL303GyKIoODyswEQKJvQCcDgoalAFFd8JQpEg7ZbCCssDEehkAn33f DMtM+LYHhoj36l36dWGThbjF =Xq79 -----END PGP SIGNATURE-----
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
participants (2)
-
Geir Bækholt -
Norman Khine