toolbox: webdev unicorns: templates (1/4)

Templating is an important way for multi-disciplined teams to work together on software projects. In addition, they serve as an important component for making applications loosely coupled and more easily understood.


Kid, the templating language isn’t working out for me very well. There are some basic things that I don’t understand how to do, despite spending weeks with it. It’s not immediately apparent how to include another template. Most templating languages let you simply include another template in place. With kid, you have to use some kind of match and extend idiom and write python to attempt to match ElementTree data structures. In addition, there is no else to match your if! For example, I can’t figure out how to easily make one of several tabs appear selected based on a variable’s value. I also had to duplicate template code for each condition if I wanted to change the structure of the document based on a variable’s value (eg if we are in mode foo, make this node a link, and this node bold, and vice versa). In addition, kid is the slowest part of my application by an order of mangitude. I’ve seen genshi, which is like kid, but has an else and is a tad faster. I’m afraid this isn’t going to cut it.

Templates: XML-based or not?

I’ve been looking at some templating language comparisons, but am having some trouble finding the comparisons I’m looking for. Clearsilver, for example, points out that generating the XML to feed into a XSLT document is a pain. But what if you use stan to generate that XML feed? I think using an XML-based templating language is ultimately more maintainable and more portable (eg, what if we switch to java/ruby/perl/D/$hot_language next year?). I’m aware than XML processing is going to be slower than general text processing, which is an acceptable cost for the maintainability and protability I think it probably provides. In addition, the graphic designer I work with is already familiar with XML technologies

Templates: Requirements

  • XML-based
  • not significantly slower than competitors
  • Designer friendly
  • Doesn’t re-parse templates spuriously (what qualifies as spurious changes depending on the environment)
  • lacks obvious security problems
  • Has idioms for including templates and rich control structures:
    • Looping:
      • ability to detect position: is the current item the last or first position?
      • ability to use counting and non counting loops: what is the index of the current item?
    • if/else
    • basic variable assignment and value manipulation (would be nice to embed a scripting language such as javascript or lua or php as well! believe it or not, there are times when some processing tools for string manipulation and such are necessary for presentation logic, not business logic; templating languages are typically notoriously bad at this, especially XSLT, but can be solved by an embedded scripting language)

There might be more… this is just a list of things off the top of my head.

This is the second of five posts discussing the web, tools to develop it, and why its important, in the context of python, code, web servers, templating, and xml technologies.

intro (0/4)
The first post, in which I explain what I’m doing.
templates (1/4)
The second post, in which I discuss templating technologies.
servers (2/4)
Third post, in which I discuss server technology, and methods I like to expose code to the web, and some performance implications.
components (3/4)
In which I discuss XML technologies for python.
conclusion (4/4)
In which I briefly mention why I’m passionate about good technology.

Post a Comment

Required fields are marked *

%d bloggers like this: