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
"Andy" == Andy McKay <andym@ActiveState.com> writes:
Andy> I can see how this would be useful in a situation where I dont have an Andy> instance of self. But in this case I do, so Im not sure how this helps. Andy> I guess you're saying once I have self I can find out what called the Andy> function. More fiddling I guess. Andy> ----- Original Message ----- Andy> From: "Martijn Pieters" <mj@digicool.com> Andy> To: "Andy McKay" <andym@activestate.com> Andy> Cc: <zope-dev@zope.org> Andy> Sent: Tuesday, September 12, 2000 11:29 AM Andy> Subject: Re: [Zope-dev] Custom dtml tag >> On Tue, Sep 12, 2000 at 09:26:49AM -0700, Andy McKay wrote: >> > Hmm well ive found i have <TemplateDict> object and of course my self. >> > Perhaps there is a pythonism I have to research here. >> > >> > ----- Original Message ----- >> > From: "Andy McKay" <andym@ActiveState.com> >> > To: <zope-dev@zope.org> >> > Sent: Monday, September 11, 2000 4:03 PM >> > Subject: [Zope-dev] Custom dtml tag >> > >> > >> > > Im playing with a custom dtml-tag along the lines of <dtm-query foo> >> > > constructs a url to a catalog query. It works fine, I would just like Andy> to >> > > extend it a bit and for this I would need to get to the calling Andy> object. >> > > >> > > For example, there will be a different query depending upon the object Andy> the >> > > dtml-query tag is contained in. Does this make sense, does anyone know Andy> the >> > > answer? >> > > >> > > Thanks in advance. >> > > >> > > -- >> > > Andy McKay, Developer. >> > > ActiveState. >> >> The namespace just reflects the attributes of the current object, plus >> whatever other tags push onto that stack (such as the in tag, which pushes >> the current element of the list it iterates over on top). >> >> If you retrieve the 'this' method from the stack, and call it, it'll >> return the topmost object on the stack. It is implemented in >> SimpleItem.Item: >> >> def this(self): >> # Handy way to talk to ourselves in document templates. >> return self >> >> -- >> Martijn Pieters >> | Software Engineer mailto:mj@digicool.com >> | Digital Creations http://www.digicool.com/ >> | Creators of Zope http://www.zope.org/ >> | ZopeStudio: http://www.zope.org/Products/ZopeStudio >> ----------------------------------------------------- >> Andy> _______________________________________________ Andy> Zope-Dev maillist - Zope-Dev@zope.org Andy> http://lists.zope.org/mailman/listinfo/zope-dev Andy> ** No cross posts or HTML encoding! ** Andy> (Related lists - Andy> http://lists.zope.org/mailman/listinfo/zope-announce Andy> http://lists.zope.org/mailman/listinfo/zope )