[Zope] dtml access to "container" within zclass

ra@burningman.com ra@burningman.com
Tue, 20 Aug 2002 15:11:47 -0700


ra@burningman.com wrote:
> Dieter Maurer wrote:
>  > ra@burningman.com writes:
>  >  > Dieter Maurer wrote:
>  >  > > Ra writes:
>  >  > >  > is there any way to gain access to an instance of a zclass 
> from a dtml
>  >  > >  > method that is within that zclass?
>  >  > > When called from ZPublisher (i.e. the Web),
>  >  > > it should run in the context of this Z instance, i.e. the instance
>  >  > > is at the top of the DTML namespace.
>  >  > > You can (under these conditions) use its "this" method to get
>  >  > > the instance itself.
>  >  >
>  >  > Alas, "this" isn't working; I get "global name 'this' is not 
> defined".
>  > Looks like the DTML Method is not called correctly (apparently, nothing
>  > on its namespace has an acquisition context).
> 
> Yep, this was it.
> 
>  > How is th DTML Method activated? Via ZPublisher? Explicitely?
> 
> I've got a dtml-method called "member_detail_html" which calls the 
> dtml-method "detail_html" within the user object.  "member_detail_html" 
> originally contained the following:
> 
> -------------
> <dtml-var header>
> 
> <dtml-if membername>
>    <dtml-var "acl_users.getItem(membername).detail_html()">
> <dtml-else>
>    <dtml-var "_.SecurityGetUser().detail_html()">
> </dtml-if>
> 
> <dtml-var footer>
> --------------
> 
> I changed "member_detail_html" like so:
> 
> --------------
> <dtml-var header>
> 
> <dtml-if membername>
>    <dtml-let userobj="acl_users.getItem(membername)">
>      <dtml-var "userobj.detail_html(userobj, REQUEST)">
>    <dtml-let>
> <dtml-else>
>    <dtml-var "_.SecurityGetUser().detail_html(_.SecurityGetUser(),
> REQUEST)">
> </dtml-if>
> 
> <dtml-var footer>
> ---------------
> 
> and it is now working.  I'm not 100% certain I've chosen the right 
> parameters to pass in, though... my best guess is that the first 
> parameter is supposed to be the "this()" object (i.e. the top of the 
> called method's namespace stack) and the second parameter should be the 
> REQUEST, if needed.  Is this correct?

Oh, never mind on this last question.  I simplified even further... the 
method now looks like this:

-------------
<dtml-var header>

<dtml-if membername>
    <dtml-with "acl_users.getItem(membername)">
      <dtml-var detail_html>
    <dtml-with>
<dtml-else>
    <dtml-with "_.SecurityGetUser()">
      <dtml-var detail_html>
    </dtml-with>
</dtml-if>

<dtml-var footer>
--------------

which is how I should have done it in the first place.

Thanks again for pointing me in the right direction!

-r