Web tool kit : pro - cons ?

David Jeske jeske at chat.net
Sun Jul 27 15:06:50 EDT 2003


On Sun, Jul 27, 2003 at 12:58:26PM +0200, vincent_delft wrote:
> >> - Build pages via templates (easy to split content and layout)
> > 
> > ZPT seems to be a good option there.
> > 
> Nice. New to me.  I've already played with Zope.... but ZPT seams to
> take the best from Templates without having the Zope constraints.

If you are not wedded to Zope for your applications, you may want to
look at Clearsilver. (http://www.clearsilver.net) It is a very mature
system which was developed at eGroups.com, and today is in use on
high-performance sites such as Yahoo! Groups and
wunderground.com. Clearsilver includes a full CGI kit which handles
form variables, cookies, etc. It also includes a PythonObject<->RDBMS
mapping system (MySQL only today, no pgsql yet), and a transparent
translation string extraction system. It is not a "server environment"
like Zope, and in fact you can use it inside of your server of choice
(Apache, Boa, IIS, Zope, etc).

I find ZPT's model for replacement hard to work with, because it tries
to fit into the xml document namespace. From the ZPT documentation
here:

  http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx

This example:

  <title tal:content="here/title">Page Title</title>

Illustrates how ZPT is making it's "tag" (i.e. tal:content) fit in as
an attribute defined by a new XML namespace. The problem is, this
constrains where you can use template commands to construct the
document. Clearsilver uses a model more like PHP where the tags exist
as items outside of the XML document parsing. This has the drawback
that your template document is not a valid XML document, but it has
the advantage that you can put the tags anywhere. 

For example, in clearsilver, you can construct URLS using sequences of
template commands, even looping. Here is a small example (whitespace
added for readability):

<a href="/url?
 <?cs each:p=CGI.Params ?>
   <?cs var:p.name ?>=<?cs var:p.value ?>&
 <?cs /each ?>"
>a_link</a>


> No.  Each part of the web page will be "boxes".  I would like to be very
> flexible and display "dynamically" some selected boxes.
> For example the same page (url) will not display the same boxes if you are
> administrator, maintener or simple viewer.

This should be pretty easy in most template systems worth their
weight. 

> An another example will be to have possibility to re-use existing boxes.  If
> I have a boxes displaying the last 5 news from Slashdot, I don't want to
> re-write it each time I need a new bacground color (for example). My Idea
> is to use those "boxes" like we use classes : if you need some modification
> you subclass it on the rest remains the same.

Clearsilver has a macro definition facility for doing just this. You
can supply arguments to macros, and even call macros recursively. Here
is a simple example:

  <?cs def:makelink(url,title,text) ?>
   <a href="<?cs var:url ?>"
      title="<?cs var:title ?>"
   ><?cs var:text ?></a>
  <?cs /def ?>

  <?cs call:makelink("http://www.python.org","Python.org website","Python.org") ?>

The paramaters can be any expressions, including constructed strings,
or data from your dynamic CGI. For example:

  <?cs call:makelink("http://" + CGI.host + "/" + CGI.script,"title","link text") ?>

As always, there are lots of systems out there, and YMMV.

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske at chat.net





More information about the Python-list mailing list