[Zope-dev] DTML Syntax contd. + rant + summary

Andrew M. Kuchling akuchlin@mems-exchange.org
Fri, 12 Nov 1999 17:41:36 -0500 (EST)


Stuart 'Zen' Bishop quoted:
>On Fri, 12 Nov 1999, David Jacobs wrote:
>> I always thought it would be nice to have a python subroutines page
>> associated with a DTML page.  It would be limited in capability like
>> PythonMethods and would be scoped to the page.  Since this would greatly
>> simplify the addition of small Python subroutines, it would ease the demand
>> on DTML to perform so much logic processing and allow it to focus on
>> presentation.

I did something similar for the American Greetings site; you had a .pd
page containing the HTML and a .py file containing Python code.  The
.py file would be executed to set up a bunch of variables, and then
their values would be substituted into the .pd.  For example, to show
the current time, you would do:

page.py:
from time import *
now = asctime(localtime(time() ))

page.pd:
The time is [now].

The templating system grew in an ugly way; first it did only variable
substitution, then I needed conditionals and hacked them in, then I
need to loop over lists and hacked that in, etc. -- very bad code, in
the end.  Another problem is that I still sometimes embedded HTML in
my Python code; one .pd page couldn't easily call another in the way
that DTML methods can.  If doing it today, I'd use DTML, because
DTML's better structure, and the ability to easily call DTML
submethods, would make this much neater.

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
Thanks. The sooner I get discouraged and quit, the more time I'll save overall.
    -- Frank Sergeant, 28 Mar 1999