[Zope] Re: page templates and "python:"

Tonico Strasser contact_tonico at yahoo.de
Mon Jul 3 10:07:27 EDT 2006


Andreas Jung schrieb:
> 
> 
> --On 3. Juli 2006 15:50:41 +0200 Tonico Strasser 
> <contact_tonico at yahoo.de> wrote:
> 
>> Claudio Battaglino schrieb:
>>> Hi,
>>> what does exactly happen when I use "python:" into a zpt?
>>> Is it a problem if I have many "python:" in my page templates?
>>
>> Path expressions are by far better human readable IMHO. I try very hard
>> to avoid Python expressions if possible.
> 
> (Un)fortunately we live a in world where methods may have parameters. 
> Path expressions work only for parameter-less methods.

This can be avoided if you "prepare" a namespace and pass it to the 
template, this way the template doesn't need to call methods.

I've written a simple page class for doing this, but it's also possible 
TTW from a Python script:

   names = {'foo': 'bar'}
   template = context.a_page_template
   return template.pt_render(extra_context=names)

Of course you can still use Python expressions if needed.

Tonico



More information about the Zope mailing list