[Zope] Avoiding acquisition aka testing for contained objects
Dieter Maurer
dieter@handshake.de
Thu, 16 Nov 2000 21:39:12 +0100 (CET)
Stefan H. Holek writes:
> If I want to know whether a certain object is contained in
> the current folder I do this:
>
> <dtml-if "'index_html' in this().objectIds()">
> yes it's here
> <dtml-else>
> not here
> </dtml-if>
>
> Id like to know whether this is the best/most efficient way to do it.
> Things like hasattr() are subject to aquisition i.e. they would find
> an index_html method along the acquisition path...
There is a trick:
<dtml-if "hasattr(aq_explicit,'index_html')">
avoids (implicit) acquisition.
How it works:
"aq_explicit" returns the explicit acquisition wrapper
for "this". This wrapper does not acquire automatically
but must be told explicitly. As "hasattr" does not to
that, it tests for an attribute of "this()" and
not an acquired attribute.
Dieter