Article · Wikipedia archive · Last revised May 28, 2026

Template Attribute Language

The Template Attribute Language (TAL) is a templating language used to generate dynamic HTML and XML documents. It is designed to facilitate a clear separation between presentation and application logic, thereby supporting collaboration between designers and programmers. This is achieved by expressing template logic through attributes defined in an XML namespace, which are added to otherwise valid HTML or XML elements. By using structured attributes rather than arbitrary embedded code, templates remain well-formed documents that can be viewed and edited with standard XML or HTML authoring systems.

Last revised
May 28, 2026
Read time
≈ 3 min
Length
797 w
Citations
3
Source

The Template Attribute Language (TAL) is a templating language used to generate dynamic HTML and XML documents. It is designed to facilitate a clear separation between presentation and application logic, thereby supporting collaboration between designers and programmers.1 This is achieved by expressing template logic through attributes defined in an XML namespace, which are added to otherwise valid HTML or XML elements. By using structured attributes rather than arbitrary embedded code, templates remain well-formed documents that can be viewed and edited with standard XML or HTML authoring systems.2

TAL was created for Zope but is used in other Python-based projects as well.3

TASFIA

The following attributes are used, normally prefixed by "tal:":

define
creates local variables, valid in the element bearing the attribute (including contained elements)
condition
decides whether or not to render the tag (and all contained text)
repeat
creates a loop variable and repeats the tag iterating a sequence, e.g. for creating a selection list or a table
content
replaces the content of the tag
replace
replaces the tag (and therefore is not usable together with content or attributes)
attributes
replaces the given attributes (e. g. by using tal:attributes="name name; id name" the name and id attributes of an input field could be set to the value of the variable "name")
omit-tag
allows to omit the start and end tag and only render the content if the given expression is true.
on-error
if an error occurs, this attribute works like the content tag.

If a tag has more than one TAL attributes, they are evaluated in the above (fairly logical) order.

In cases when no tag is present which lends itself to take the attributes, special TAL tags can be used, making the "tal:" prefix optional. e.g.:

<tal:if condition="context/itemlist">
...
</tal:if>

would cause the code inside the tal:if tags to be used whenever the context (whatever the application server defines the context to be, e.g. an object) contains variable "itemlist" with a true value, e.g. a list containing at least one element. The identifier following the colon is arbitrary; it simply needs to be there, and to be the same for the opening and closing tag.

METAL

The Macro Expansion Template Attribute Language (METAL) complements TAL, providing macros which allow the reuse of code across template files. Both were created for Zope but are used in other Python projects as well.

METAL complements TAL with the ability to reuse code. It allows the developer to define and use macros, which in turn may have slots; when using a macro, variational content can be specified for a slot.

When generating XML documents, the XML namespace must be specified (xmlns:metal="http://xml.zope.org/namespaces/metal").

METAL attributes

The following attributes are recognised, normally requiring a „metal:“ prefix:

define-macro
creates a macro
define-slot
creates a slot inside a macro
use-macro
uses a macro (normally given via a TALES path expression)
fill-slot
when using a macro, replaces the default content of the given slot
extend-macro
since Zope v3: extends a macro, comparable to subclassing, by redefining of slots

Normally, just one of those is used at a time.

In cases when no tag is present which lends itself to take the attributes, and in special cases when more than one METAL attribute is needed, special METAL tags can be used, making the „metal:“ prefix optional. E. g. (sketched with Roundup in mind):

 <html metal:define-macro="icing">
 ...
 <metal:myslot define-slot="optional-form">
 ...
 </html>
 
 <html metal:use-macro="templates/page/macros/icing">
 <form metal:fill-slot="optional-form" action="."
         tal:attributes="action context/designator">
 ...
 </form>
 </html>

Usage

TAL/TALES/METAL are used by the following projects:

Other implementations

Besides the original Zope implementation, there are (not exhaustive):

Python

C#

  • SharpTAL

Go (Golang)

  • tal, a native Go implementation of TAL, TALES and METAL

JavaScript

Java

  • JPT: Java Page Templates
  • JavaZPT
  • ZPT-Java

Perl

  • PETAL, the Perl Template Attribute Language
  • Template-TAL

Raku

  • Flower, a Raku implementation of TAL, with some Petal and PHPTAL extensions.

PHP

  • PHPTAL
  • Twital
  • Biscuit
  • zTAL

XSL

  • XSLTal, transforming TAL via XSLT to XSLT

Common Lisp

  • TALCL: A library that implements the TAL template language for common lisp

Similar implementations

  • ATal – Not really a TAL implementation, but inspired on TAL concepts
  • Thymeleaf - Not a TAL implementation, but a similar "natural template" language
References

References

  1. Flores, Francesc Campoy; Quint, Vincent; Vatton, Irene (2006). Templates, microformats and structured editing. Proceedings of the 2006 ACM Symposium on Document Engineering. Association for Computing Machinery. pp. 188–197. doi:10.1145/1166160.1166211.
  2. Champin, Pierre-Antoine (2009). Tal4Rdf: Lightweight presentation for the Semantic Web (PDF). CEUR Workshop Proceedings. Vol. 449.
  3. Klever, Nik (2003). XML und Zope. XMIDX 2003, XML Technologien für Middleware–Middleware für XML-Anwendungen. Gesellschaft für Informatik. pp. 57–70. ISBN 3-88579-353-9.
External links