An introduction to SimpleTAL

About SimpleTAL

What is SimpleTAL?

SimpleTAL is an independent implementation of the TAL and METAL languages.  TAL is the language used in Zope to power ZPT (Zope Page Templates), and is a nifty template language.  An example is worth a thousand words, so here's a simple example of a TAL template that demonstrates the simplicity and power of the language:


<html>
<body>
<h1 tal:content="title">
<h2 tal:condition="username">Welcome back <b tal:replace="username">Username here</b></h2>
<p>
Hot topics for today are:
<ul>
  <li tal:repeat="news hotItems">
  	<a tal:attributes="href news/link" tal:content="news/title">News item</a>
  </li>
</ul>
</p>
</body>
</html>

TAL does not allow you to send emails, access databases or write games - it is a pure templating language for laying out dynamic content in either a HTML or XML template.  TAL is written in Python, and so can be used by any Python program that wishes to generate HTML or XML.

The example above demonstrates most of what the TAL language can do:

  • Include content into an element (tal:content)
  • Replace an element (tal:replace)
  • Conditionally include part of a template (tal:condition)
  • Add attributes to an element (tal:attributes)
  • Repeat a piece of a template once for each entry in a list (tal:repeat)
  • Define variables (not shown - tal:define)
  • Conditionally omit tags (not shown - tal:omit-tag)

The definition of TAL, and the best reference to learn it from, is the Zope documentation.  There are examples of how to use SimpleTAL included in the download, as well on my example page.  Additionally, I've documented the API to SimpleTAL, and written some notes which document the differences between SimpleTAL and the Zope implementation.

A brief history

SimpleTAL was written because I wanted to be able to use the TAL language in my weblog software, and I didn't want to have to install or use the full Zope system to do this.  I initially tried using the testing infrastructure of Zope's implementation (DummyEngine.py), but found that its lack of support for most of the expression language (TALES) a road block.  I then hacked together a new implementation myself, which I eventually released in the hope that it may be of use to someone else.

In an attempt to improve the performance of the template engine I started to refactor it, an effort that lead to the creation of version 2.0.  This version, as well as bringing a very significant performance gain, also improves the API, fixes a few bugs, and adds a good many test cases.  For information on moving from SimpleTAL 1.x to 2.x see the Readme file included in the download, or the notes page.

METAL support was added in version 3.0, which is backwards compatible with the version 2.x series of releases.

Return to SimpleTAL

%nbsp;

Last Modified: Thu, 03 Jul 2003 21:39:31 BST

Made with PubTal 3.2.0

Copyright 2007 Colin Stewart

Email: colin at owlfish.com