[ale] Templates (was: [ale] Need a PHP/MySQL intern...)

Joseph A Knapka jknapka at earthlink.net
Wed Mar 13 19:09:53 EST 2002


jb wrote:
> 
> Ok...educate me here please.
> 
> I'm not sure I see any real benefit of using templates aside from making
> your code look a bit prettier for someone who might be php illiterate or
> terrified of non-html source.  Looking at Smarty for an example, it
> would seem that all (and forgive me if I'm wrong...this after a cursory
> look ;-)) it provides is merely another layer of abstraction on top of
> php...function calls that look different from actual function calls but
> are still function calls...if/then/elses and loops likewise.
> 
> Where's the benefit? As far as being able to affect all pages on a site
> with a single line change, can't you do this by including a general file
> that would set a var like $background, or $fontcolor, etc.?  As far as
> separating presentation from business logic, can't this be accomplished
> by function calls or objects (i.e., have a set of function libs or
> classes specifically to handle bus. logic, and have your display code
> make calls to these resources)?

That is easier said than done.

> Is Zope in someway different?

I don't know anything about Smarty (or PHP, for that matter),
but the advantage of page templates (as implemented in Zope,
anyway) is this: a web designer (that is, a
graphic-artist-wysiwyg-what-the-heck-is-code?
type of person) can lay out every page on the site, in the
HTML design tool of her choice, including "typical" sample
content. The pages, designed in this way, are 100% functional
static HTML pages, with no logic behind them. They can be used
to demo the site, validate usability to some extent, and so
forth.

A programmer can then implement all the site logic by adding
namespaced ZPT attributes to the HTML code. The resulting pages
are *still* 100% functional static HTML, and can still be
edited by the page designer's WYSIWYG HTML tool - but when
served by Zope the ZPT attributes cause the sample content
to be replaced by the output of whatever business logic
the programmer has implemented.

For example, the page designer writes:

<P>
This is the introduction paragraph from the WhizBang
web site.
</P>

The programmer modifies it thus:

<P tal:content="python:getIntroText()">
This is a sample paragraph from the WhizBang web site.
</P>

The tal:content attribute causes Zope to replace the
contents of the <P> tag with the output of the
"getIntroText()" function call when serving the page,
so that what the client sees is something like,

<P>
Welcome to WhizBang Industries! We rule! Give us
your money!
</P>

All of ZPT works this way, and the result is that
designers do what they do best, programmers do what
they do best, and they don't have to deal with each
other's stuff (much).

This is different than schemes like DTML (Zope's
"old" templating language) and apparently PHP (from
the few samples of PHP code I've seen), in that
ZPT code is always also valid HTML, and thus can be
viewed and edited in raw form by most HTML design
tools. DTML and PHP muck up the page with nonstandard
tags which normal HTML editors have to (1) ignore,
(2) choke on, or (3) be taught how to handle. Further,
DTML and PHP tangle logic irretrievably up with
presentation, so that designers must become programmers
and vice versa in order to get any work done.

Cheers,

-- Joe
  Using open-source software: free.
  Pissing Bill Gates off: priceless.

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list