[Zope] On DTML and Python Script

Phill Hugo phill@fortune-cookie.com
Tue, 05 Dec 2000 17:00:26 +0000


Jason Leach pointed out that Document Template could include ASP/PHP
style Python escapes to embed code. This may seem a good idea at first
but part of the really nice thing about Zope is that it goes a fair way
to ensure you organise your work cleanly and seperate logic from the
layout.

In PHP I always use FastTemplate which offers pretty much only what
<dtml-var VARIABLE_NAME> does (that doesn't include <dtml-var
"VAR1+VAR2"> or anything "clever"). The benefit of having no logic in
your HTML is huge when you have multiple people working on the project.
The "creep" of template systems to hold more and more logic such as
Loops, Conditions etc is forgivable as it allows basic programming to be
done by the HTML people but strictly it isn't necessary as long a
variable insertion / tag replacement is possible.

If you are "having to [use] all those dtml tags" then you're probably at
the point where replacing that big chunk with <dtml-var welcomeMessage>
is in order. This could be anything you want (Python method, External
Method, DTML method etc) which does the real logic and conditionally
returns its output to the master template (that content possibly from
another smaller, reused DTML method - it amazing how many sites use the
same text all over it (like Next 10, Prev 10 for example!).

At that point you've removed any fear of the HTML people walking over
your code with a bulldozer and it means they can update things while you
do.

What I'm suggesting is that <%, <?php and <%py are Bad Things. If you
want them, use ASP with Python hosted inside or PHP. Much of the benefit
of Zope is that it keeps things elegant. The overhead of splitting
things up so much is small when you start to reuse the bits (by my
milage this is on regular occasion).

Even the <dtml-if>, <dtml-in> and <dtml-let> tags could be argued to be
Bad Things but they are convenient in some cases (they are easy for HTML
writers to understand and can be used for simple things by them).

I don't really see the "convenience" of a Python code escape as its just
as easy to make a Python Method and pop <dtml-var MyPythonMethod> in its
place keeping things neat.

Still, I suppose it'd hardly matter if it was available, those who agree
with the above would probably ignore it, much as I ignore it in PHP and
use FastTemplate instead.

Phill