[Zope] How do I check for existence of a page?
Dieter Maurer
dieter@handshake.de
Wed, 28 Feb 2001 21:00:36 +0100 (CET)
You should not use a "dtml-in" to check for the existence of
an object. You should directly check for the object:
I many cases, you can use
<dtml-if "_.hasattr(aq_explicit,'attrname')">
or
<dtml-if "_.hasattr(object.aq_explicit,'attrname')">
to check whether the current object or "object", respectively,
has attribute "attrname".
In some rare cases, this can give you a "true" result,
even though the object does not have an 'attrname'.
A save way is an external method "baseHasAttr" defined by
def baseHasAttr(object,attrname):
obj= getattr(object,aq_base,object)
return hasattr(obj,attrname)
and a test through
<dtml-if "baseHasAttr(this(),'attrname')>
or
<dtml-if "baseHasAttr(object,'attrname')>
Dieter