[Zope3-Users] Weird behaviour of ViewPageTemplateFile()
Jim Fulton
jim at zope.com
Thu Apr 10 18:14:21 EDT 2008
On Apr 10, 2008, at 2:59 PM, Martin J. Laubach wrote:
>>> > ViewPageTemplate must be in the view's namespace, and it magically
>>> > fishes out the view, view's context and request, and makes them
>>> > available in the TAL namespace.
>>>
>>> Ah, so there _IS_ heavy magic involved here. Thanks for
>>> clarifying that, I was already doubting my sanity!
>>
>>
>> This is exactly the same magic that methods use.
>> ViewPageTemplateFiles
>> are, like functions, meant to be used as methods and to be bound to
>> instances.
>
> Okay, then this leads me to the strong suspicion that what I'm
> (mis)using ViewPageTemplateFiles for is the wrong way to attack
> the problem.
>
> What I'm doing is something along the lines of
>
> class MyView(BrowserView):
> def __call__(self):
> pagename = somehow_compute_new_page_name(self.request,
> self.context)
> pt = ViewPageTemplateFile(pagename)
> return pt.__get__(self, self.__class__)()
>
> but quite obviously, that's not how it's meant to be used, is it...
> Perhaps I need a radically different approach?
Need is too strong. You might prefer another approach based on what
you now know. :)
Fred suggested using a page-template class that doesn't behave as a
method.
Another option might be to create a bunch of methods and then have
your function dispatch to those, depending, of course, on how many
there are.
Jim
--
Jim Fulton
Zope Corporation
More information about the Zope3-users
mailing list