[Zope] Method Context Control

Amos Latteier amos@aracnet.com
Wed, 03 Feb 1999 15:16:32 -0800


At 01:59 PM 2/3/99 -0800, Michael Bernstein wrote:
>Michael Bernstein wrote:
>> 
>> Pavlos Christoforou wrote:
>> >
>> > On Tue, 2 Feb 1999, Michael Bernstein wrote:
>> > >
>> > > If this is not currently possible, I would like to suggest that a
>> > > 'context' attribute be added to <!-- #var -->, with the default being
>> > > 'context=here' (the current behaviour) and an additional value of
>> > > 'context=self' or perhaps 'context=origin' being made available.
>> >
>> > <STUFF DELETED>
>> > How should the relative URL's or BASE variables be handled if this
>> > document is called from a subobject down the
>> > object hierarchy like <!--# var global_map context=origin--> ?
...
>Ok, last chance for anyone to get their two cents in before I submit
>this as a feature request. If you feel this is a good/bad idea, or that
>I missed something crucial, let me know (privately if neccessary).

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?

-Amos