Template Attribute Language
|This article does not cite any references or sources. (January 2012)|
||The topic of this article may not meet Wikipedia's general notability guideline. (January 2012)|
The Template Attribute Language (TAL) is a templating language used to generate dynamic HTML and XML pages. Its main goal is to simplify the collaboration between programmers and designers. This is achieved by embedding TAL statements inside valid HTML (or XML) tags which can then be worked on using common design tools.
The following attributes are used, normally prefixed by "
- creates local variables, valid in the element bearing the attribute (including contained elements)
- decides whether or not to render the tag (and all contained text)
- creates a loop variable and repeats the tag iterating a sequence, e.g. for creating a selection list or a table
- replaces the content of the tag
- replaces the tag (and therefore is not usable together with content or 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 "
- allows to omit the start and end tag and only render the content if the given expression is true.
- 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.
The Macro Expansion Template Attribute Language 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 (
The following attributes are recognised, normally requiring a „
- creates a macro
- creates a slot inside a macro
- uses a macro (normally given via a TALES path expression)
- when using a macro, replaces the default content of the given slot
- 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>
TAL/TALES/METAL are used by the following projects:
Besides the original Zope implementation, there are (not exhaustive):
- SimpleTAL (http://www.owlfish.com/software/simpleTAL/, TAL-guide)
- OpenTAL (http://savannah.nongnu.org/projects/opental/)
- ZPT (http://zpt.sourceforge.net/), a standalone version of Zope Page Templates
- Chameleon (http://chameleon.repoze.org/), a fast reimplementation of Zope Page Templates
- SharpTAL (http://sharptal.codeplex.com/)
- jstal (http://code.google.com/p/jstal/)
- Distal (http://code.google.com/p/distal)
- DomTal (https://github.com/drslump/DomTal)
- JPT: Java Page Templates (http://christophermrossi.com/jpt/)
- JavaZPT (http://javazpt.sourceforge.net/)
- PETAL, the Perl Template Attribute Language (https://metacpan.org/module/Petal)
- Template-TAL (https://metacpan.org/module/Template::TAL)
- Flower, a Perl 6 implementation of TAL, with some Petal and PHPTAL extensions. (https://github.com/supernovus/flower/)
- PHPTAL (http://phptal.org)
- Twital (https://github.com/goetas/twital)
- Biscuit (http://bitbucket.org/infiniteshroom/biscuit)
- XSLTal, transforming TAL via XSLT to XSLT; http://svn.bitflux.ch/repos/public/popoon/trunk/components/transformers/xsltal/tal2xslt.xsl
- ATal – Not really a TAL implementation, but inspired on TAL concepts
- Thymeleaf - Not a TAL implementation, but a similar "natural template" language