[Zope-dev] Acquisition in a DTML Tag

Shane Hathaway shane@digicool.com
Thu, 07 Sep 2000 14:03:46 -0400


Brett Carter wrote:
> 
> >>>>> "Brett" == Brett Carter <brett@kavi.com> writes:
> 
>     Brett> I've defined my own dtml tag (i.e. <dtml-foo></dtml-foo>)
>     Brett> and I am trying to look up an object depending on the
>     Brett> arguments passed to my tag.  The python class that defines
>     Brett> the tag inherits from Acquisition.Implicit, but 'self'
>     Brett> doesn't contain any of the Acquisition hiarchy.  It seems
>     Brett> like this must be possible, since the <dtml-var> tag must
>     Brett> have to do an object lookup somewhere for objects passed to
>     Brett> it to render.  Can anybody shed some light on this?  Is it
>     Brett> doable?  TIA -Brett
> 
> Ok, So after some *major* hacking, i've realized that the 'md' passed
> into the render() method of my dtml tag contains the namespace, and is
> of type 'TemplateDict' which appears to contain a stack of
> 'MultiMapping's.  Weird.  Well, anyways, I just used the 'has_key' and
> 'getitem' methods to lookup my item.  The question now is how do I
> create a new object in the current namespace?  It looks like the
> TemplateDict is a read-only type of data structure.  Anybody?  TIA
> -Brett

Look at render() of DT_With.py.  It does an md._push(<mapping containing
new names>) then, in a try/finally clause, calls
DT_Util.render_blocks().  In the finally clause, it does md._pop().

Shane