Template Attribute Language
Encyclopedia
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.
TAL was created for Zope
but is used in other Python
-based projects as well.
would be treated by a common HTML design tool as
while the application server, evaluating the tal:content attribute, would yield
Of course, string literal
s are not the most common nor the most useful use case; syntax of the possible attribute values are properties of the TAL Expression Syntax (TALES) language. In Python
-based implementations, it is possible to use Python expressions.
Using METAL
(Macro Expansion TAL) it is possible to re-use code from other templates.
When generating XML documents, it is important to specify the XML namespace
define
condition
repeat
content
replace
attributes
omit-tag
on-error
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 "
would cause the code inside the
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
(
define-macro
define-slot
use-macro
fill-slot
extend-macro
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):
implementation, there are (not exhaustive):
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
and XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
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.
TAL was created for Zope
Zope
Zope is a free and open-source, object-oriented Web application server written in the Python programming language. Zope stands for "Z Object Publishing Environment", and was the first system using the now common object publishing methodology for the Web...
but is used in other Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
-based projects as well.
Overview
TAL templates are often made from result pages with the variable content being replaced by special attributes; e.g.,would be treated by a common HTML design tool as
while the application server, evaluating the tal:content attribute, would yield
Of course, string literal
String literal
A string literal is the representation of a string value within the source code of a computer program. There are numerous alternate notations for specifying string literals, and the exact notation depends on the individual programming language in question...
s are not the most common nor the most useful use case; syntax of the possible attribute values are properties of the TAL Expression Syntax (TALES) language. In Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
-based implementations, it is possible to use Python expressions.
Using METAL
Metal
A metal , is an element, compound, or alloy that is a good conductor of both electricity and heat. Metals are usually malleable and shiny, that is they reflect most of incident light...
(Macro Expansion TAL) it is possible to re-use code from other templates.
When generating XML documents, it is important to specify the XML namespace
xmlns:tal="http://xml.zope.org/namespaces/tal"
Attributes
The following attributes are used, normally prefixed by "tal:
":define
- creates local variables, valid in the elementHTML elementAn HTML element is an individual component of an HTML document. HTML documents are composed of a tree of HTML elements and other nodes, such as text nodes. Each element can have attributes specified. Elements can also have content, including other elements and text. HTML elements represent...
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 variableVariable (programming)In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...
"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.: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 complements TAL, providing macros which allow the reuse of code across template files. Both were created for ZopeZope
Zope is a free and open-source, object-oriented Web application server written in the Python programming language. Zope stands for "Z Object Publishing Environment", and was the first system using the now common object publishing methodology for the Web...
but are used in other Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
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
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
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 ZopeZopeZope is a free and open-source, object-oriented Web application server written in the Python programming language. Zope stands for "Z Object Publishing Environment", and was the first system using the now common object publishing methodology for the Web...
v3: extends a macro, comparable to subclassingClass (computer science)In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
, 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
Roundup (issue tracker)
Roundup is an open-source issue or bug tracking system featuring a command-line, web and e-mail interface. It is written in Python and designed to be highly customizable. Roundup was designed by Ka-Ping Yee for the Software Carpentry project and has been developed since 2001 under the direction of...
in mind):
Usage
TAL/TALES/METAL are used by the following projects:- ZopeZopeZope is a free and open-source, object-oriented Web application server written in the Python programming language. Zope stands for "Z Object Publishing Environment", and was the first system using the now common object publishing methodology for the Web...
(web application server) - Roundup (issue tracker)Roundup (issue tracker)Roundup is an open-source issue or bug tracking system featuring a command-line, web and e-mail interface. It is written in Python and designed to be highly customizable. Roundup was designed by Ka-Ping Yee for the Software Carpentry project and has been developed since 2001 under the direction of...
- Simplicity PHP framework
Other implementations
Besides the original ZopeZope
Zope is a free and open-source, object-oriented Web application server written in the Python programming language. Zope stands for "Z Object Publishing Environment", and was the first system using the now common object publishing methodology for the Web...
implementation, there are (not exhaustive):
Python
- 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
Java
- JPT: JavaJava (programming language)Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
Page Templates (http://christophermrossi.com/jpt/) - JavaZPT (http://javazpt.sourceforge.net/)
Perl
- PETAL, the PerlPerlPerl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
Template Attribute Language (http://search.cpan.org/dist/Petal/) - Template-TAL (http://search.cpan.org/dist/Template-TAL/)
Perl 6
- Flower, a Perl 6Perl 6Perl 6 is a major revision to the Perl programming language. It is still in development, as a specification from which several interpreter and compiler implementations are being written. It is introducing elements of many modern and historical languages. Perl 6 is intended to have many...
implementation of TAL, with some Petal and PHPTAL extensions. (http://github.com/supernovus/flower/)
XSL
- XSLTal, transforming TAL via XSLTXSLTXSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...
to XSLTXSLTXSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...
; http://svn.bitflux.ch/repos/public/popoon/trunk/components/transformers/xsltal/tal2xslt.xsl
Common Lisp
- TALCL: A library that implements the TAL template language for common lispCommon LispCommon Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 , . From the ANSI Common Lisp standard the Common Lisp HyperSpec has been derived for use with web browsers...
Similar implementations
- ATal – Not really a TAL implementation, but inspired on TAL concepts