Document Actions

Templating Systems Compared and Contrasted

Filed Under:

By Chris Withers from Simplistix Ltd

Independent Zope and Python consultant. Using Zope and Python since 1999.

Python 2.4 gives string templating, which is better than e.g. print statements.

Quixote - PTL:

import quixote quixote.enable_ptl()

Positives:

  • allows template re-use

Negatives:

  • broken html possible
  • what would an html-only person think?

Zope - DTML:

  • It is a generic scripting language
  • Highly tied to acquisition
  • Tell the html writers to leave the dtml variable alone and they can do the rest.

Positives:

  • simple templates
  • not just xml/html

Negatives:

  • acquisition
  • one big namespace
  • not good with dreamweaver and friends

Zope - ZPT

Well known in the Zope community.

Positives: - Clean namespaces

  • limits you from introducing business logic in templates
  • source is valid xml/html

Negatives:

  • 2 or 3 new languages
  • macros are confusing, especially nesting them
  • very tied to Zope
  • tied to generating xml/html

Cheetah

  • not limited to xml
  • not tied to one framework

Positives:

  • familiar, python-like
  • compact
  • caching

Negatives:

  • not enough python-like, so yet another language
  • we're not helping the web monkeys

Nevow: really aimed at twisted.nevow

Positives:

  • Clean separation of data, logic and presentation
  • does help the web monkeys

Negatives:

  • very verbose
  • meant for Twisted and yes it is twisted!

Others: - Myghty

  • Preppy
  • XSLT
  • PyMeld, meld2, meld3
  • Kid attribute language like ZPT

Types: preprocessor, class based, attribute languages, DOM based

We want to:

  • Replace attributes, values and tags.
  • Repeat tags
  • Remove attributes, values, tags and node
  • html quoting

What if we did that?

  • simple
  • no new languages
  • work with raw html

Twiddler

  • n = t.getById(Something)
  • n.replace(value, tag, **attributes)
  • n.repeat(value, tag, **attributes)
  • n.remove()
  • Put code in html comments, mostly at the top.
  • t.clone() for reusing common material
  • Use name attributes:

Positives:

  • works with real html
  • no new language
  • simple as possible

Negatives:

  • verbose
  • not battle-proven
  • maybe slow

I hadn't seen meld3 when i started developing Twiddler, but they are scarily similar. It uses meld:id attribute.

But it's not just about html. Think about sending an email. Or a css file. Or things that are just not xml.

What about i18n, html quoting, stx, rst? We can do that.

See the presentation.