[Zope] Method Context Control

Michael Bernstein mbernstein@profitscape.net
Wed, 03 Feb 1999 15:36:49 -0800


Amos Latteier wrote:

> Hmm. This request doesn't seem that clear to me. As I understand it, you
> want the ability to call methods on specific objects. If this is the case,
> why not use expressions:
> 
> <!--#var expr="obj1.obj2.method()"-->
> 
> rather than
> 
> <!--#var method context="obj1.obj2"-->
> 
> It's true that var does a little magic, so perhaps these constructs aren't
> exactly the same. But this doesn't seem like a big deal to me considering,
> you can do the magic with the special 'render' function:
> 
> <!--#var expr="_.render(obj1.obj2.method)"-->
> 
> If what you want with the 'context' option is an easy way to refer to the
> root object try this:
> 
> <!--#var expr="PARENTS[-1]"-->
> 
> So if you want to render a method, say 'global_map' in the context of the
> top-level object, try this:
> 
> <!--#var expr="_.render(PARENTS[-1].global_map"-->
> 
> Or do I misunderstand what you want to do?

Here is a section of my original posting:

> How can I control the context within which the various built in methods
> execute?
> 
> For example, I am using a tree tag in a document method to display
> subfolders in my global navigation. However, when this method is
> acquired by a subfolder, its context changes and it only lists the
> subfolders of the current folder. I want to force this method to execute
> within its original context in order to display the entire site
> structure regardless of the page being viewed.

In other words, I want to be able to force a method to render as if it
had never been acquired.

If the method is being acquired from the site root, 'context=origin'
would force it to render within the context of the site root. However,
if the method is being acquired from a sub-folder, it would force the
method to render using the context of that sub-folder.

I'm not quite sure that the code you posted isn't what I need, so
forgive me if I'm restating the obvious.

Thank you for your attention,

Michael Bernstein.