Thanks for the hint. After some experimentation I realise that "exists:" does not help, because it does not have an "else" branch. If I set the exists condition on the body or a span tag, the defined results are visible only within that tag. An else branch must me simulated by a second condition on a tag, but that means that the whole content of the previous one needs to be repeated. However, the whole point of the test was to re-use all the content except for a single statement at the beginning that determines where the results come from. As a result, a neater solution seems to be to have two ZPTs with a single different line (maintenance problem). regards Andre Jean-Francois.Doyon@CCRS.NRCan.gc.ca wrote:
Yes, use the "exists:" TAL expression. So you would do:
<span tal:condition="exists: here/request/results" />
or something like that ...
More info in the ZPT reference ...
J.F.
-----Original Message----- From: zope-bounces@zope.org [mailto:zope-bounces@zope.org]On Behalf Of Andre Meyer Sent: Monday, March 15, 2004 5:41 AM To: Zope List Subject: [Zope] hasattr in tal:condition
Dear Zopers
Is it the case that it is not possible to make use of hasattr within a tal:condition statement? In a ZPT I need to test whether an attribute of here/request is set or not. Unfortunately, this raises an exception, which is exactly what I want to prevent...
Here is what the test looks like:
<span tal:condition="python:test(hasattr(request, results), 1, 0)">span</span>
Is there a better way to achieve the same?
thanks and regards Andre
PS in the full version the statement looks as follows:
<body tal:define="results python:test(hasattr(request, results), request.results, here.Catalog()); ... >
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )