[Zope-dev] Custom dtml tag
Brett Carter
brett@kavi.com
13 Sep 2000 09:51:08 -0700
Andy - looking up 'this' in a dtml method or document won't work
unless you expose it in your python product/tag definition. I'm
talking about getting 'this' inside a dtml tag that I have defined
myself (i.e. <dtml-foobar></dtml-foobar>). If you want 'this'
available in dtml, write an external method and just return 'self'
def this(self): return self
-Brett
>>>>> "Andy" == Andy McKay <andym@activestate.com> writes:
Andy> Really? Ive looked up this and get nothing (an attribute error actually) and
Andy> its not in globals. If that would work that would be great - but a it
Andy> certainly doesnt seem to on a standard DTMLDocument / Method.
Andy> ----- Original Message -----
Andy> From: "Brett Carter" <brett@kavi.com>
Andy> To: "Andy McKay" <andym@activestate.com>
Andy> Cc: <zope-dev@zope.org>
Andy> Sent: Tuesday, September 12, 2000 4:17 PM
Andy> Subject: Re: [Zope-dev] Custom dtml tag
>> Andy: here's what I've gleaned - in a dtml tag's render() method, you
>> get passed in self and a template dict, in my example let's call it
>> 'md'. md is essentially a stack/dictionaryish object of the *current*
>> namespace - and one of the handy things that's always around in the
>> namespace is the 'this' function, which returns the object on the top
>> of the stack.
>>
>> Just lookup 'this', run it, and there you have a reference to the
>> calling object! Ex:
>>
>> def render(self, md)
>> this = md.getitem('this')
>> callingObj = this()
>> return "Calling object was %s" % (callingObj.id())
>>
>> Note I haven't tested this code. Good luck!
>> -Brett
>>