[Zope] Using tal and no dmtl.
Tino Wildenhain
tino@wildenhain.de
Thu, 12 Jun 2003 01:22:31 +0200
Hi,
John Kipling Lewis wrote:
> On Fri, 30 May 2003, Dmitry Dembinsky wrote:
>
>
>>We use tal:define for this purpose:
>>
>> <body tal:define="dummy python:foo(); <other assignments>" ...
>>
>>Usually this way we run some page setup code which we put inside <body>
>>or even top-level <html> tag.
>
>
> We have done this as well. It just seemed an obvious hole in the tal
> system. There should be a way to execute arbitrary code in tal.
> Something like:
>
> <body tal:run="python:foo()">
>
> John -
I have to disagree whith this. Even tal:define is somewhat ugly.
The design goal has to be to remove as much application code
as possible from template. So always set up your data outside
of the template.
A handy way is to have a simply python script "dispatcher"
method which calculates all values and stuff and then
returns the actual template like this:
-- python script --
contect.callSomething()
val=context.calculateSomething()
return context.Template(values=val)
-- /python script--
in this example you can access values
thru options/values in TAL.
This is clean and handy.
You even can return different templates according to
a condition and set header information and so on.
HTH
Tino Wildenhain