Thursday, June 02, 2005

Python: HTMLTemplate

Paul Abrams suggested to me the idea of having 100% pure HTML, and then using some DOM on the server side to splice chunks of HTML together. After talking about it for about two hours, I became excited about the idea, and I wondered if it would be pleasant in practice in contrast to, say, Cheetah. At the very least, it would be an interesting alternative.

It turns out that HTMLTemplate is one such system. I asked the Python web-sig about it, as well as a few other people. Tung Wai Yip said that he really liked HTMLTemplate. I figured my buddy, Donovan Preston, of Nevow fame would like it because he's a fan of getting away from the whole "big chunk of HTML in an amorphous string" idea. Ian Bicking had the following comment, which I feel was very perceptive:

If there's no code then it's not a presentation layer. It's an HTML layer, nothing more, just dumb data. Presentation requires logic.

Ksenia Marasanova, the newest member added to the Aquarium project, had the following comments based on real experience:

I used it quite a lot, and while it is fast, bugs free and simple to use, total separation of markup and code is IMHO contraproductive - every simple change mostly requires changing two files.

Since Ksenia's opinion is based on experience, it carries a lot of weight in my mind. Feel free to add your comments below.


Shannon -jj Behrens said...

If Paul Abrams were here, instead of taking care of his newly born child, he might object to my statement that HTMLTemplate is similar to his idea. HTMLTemplate is based on doing callbacks based on various HTML tag attributes. In contrast, in Paul Abrams' idea, the template was completely inactive, and the server was responsible for pro-actively modifying the DOM. I think the various comments above still apply.

pbx said...

Belatedly coming across this post -- just wanted to mention PyMeld also:

I have to say, while I find these types of systems really fun to play with, for plain ol' web apps I haven't yet found a situation that really calls for them. I get a lot more mileage out of a good text-based tempating system (e.g. Django's) that supports template inheritance.

livingcosmos said...

not only that, but check out
Meld3 before passing judgement on Python approaches to separating HTML and Python code.

Anonymous said...

Saying that there is "no code" in simple template systems, such as Hamish Sanderson's HTMLtemplate, is misleading. My attraction to these minimalistic systems is related to my attraction to Python. They both "get out of your way". Embedded tag attributes, to be interpreted by the templating engine, are in fact pointers, since they are the names of, or parameters to, code objects which are applied to the associated tag / block. The fact that the raw templates are transparent to a browser's rendering engine is a very great advantage, which implies that a "web designer's" tool of choice (cough Dreamweaver cough) will also safely ignore the attribute:value pairs. When it comes to keeping a production pipeline running (design -> code -> test -> publish), including (especially!) round-tripping, when design / functionality is updated, simplicity is the name of the game!

Re. editing "at least two files", if the changes to those multiple files are simple, and comprehensible, it can still be much more effective than wrangling a single "intertwingled" template file which both designers and coders must "grok", or at least not break, during updates.

Shannon -jj Behrens said...

I've been doing Web development for a long time, and I have always preferred a different work style.

I prefer designers to give me HTML templates, and then I integrate them into the system. Many designers don't even know how to create semantic HTML or organize CSS properly, so I often don't rely on them for anything other than design.

On the other hand, for more technical designers, I often help them setup a build environment so that they can edit templates running live using a normal text editor.

Personally, I refuse to allow anything from DreamWeaver into a real application.