Template Attribute Language
The Template Attribute Language ( TAL , roughly translated: “Attribute-based template language”) is a template language for generating HTML and XML (and thus also XHTML ) pages. Its aim is to facilitate the collaboration between designers and programmers by making both the templates and the results pages valid documents in their markup language . The templates can therefore be edited with design tools that don't know anything about TAL, but leave unmolested attributes unmolested.
The TAL was created within the framework of the Zope web application server ; they usually speak of Zope Page Templates .
TAL completely abstracts from the programming language used; only the language used for expression evaluation (usually TALES ) can allow language-specific expressions depending on the implementation, mostly in Python .
overview
TAL templates are created as result documents in which the variable content is overridden by special attributes; Program code outside of elements such as B. in PHP or JSP is not necessary. In the following example, the element <h1>
<h1 tal:content="string:Eine völlig andere Überschrift">
Für den Designer sichtbare Überschrift
</h1>
from a common HTML editor as
<h1>
Für den Designer sichtbare Überschrift
</h1>
handled while the application of the template by the application server
<h1>
Eine völlig andere Überschrift
</h1>
results. Specifying a constant string is of course a rather negligible case in practice; the possible attribute values are defined by the TAL Expression Syntax ( TALES ). For example, Python expressions can be used in the existing Python implementations .
If XML documents are to be generated, it is important to enter the XML namespace ( xmlns:tal="http://xml.zope.org/namespaces/tal"
).
Macros
With the help of METAL (Macro Expansion TAL) it is possible to reuse code across template boundaries.
internationalization
With the help of the i18n
attributes (see i18n TAL ) localized pages can be generated.
Attributes
The following attributes are recognized, which normally tal:
have to be preceded by the prefix :
- define
- creates valid, local variables within the block defined by the element
- condition
- decides whether the element is created
- repeat
- creates a loop variable that is used to iterate over a sequence, e.g. B. to create a selection list or a table
- content
- replaces the content of the element
- replace
- replaces the element (and therefore cannot be used together with content or attributes)
- attributes
- replaces the specified attributes (e.g. the
tal:attributes="name name; id name"
name and ID attribute of an input field could be defined using the variable "name") - omit-day
- allows the tag to be omitted dynamically and only the content to be displayed
- on-error
- will be executed if an error occurs and then works like "content"
If an element has several TAL attributes, these are evaluated (regardless of the order in which they are listed) in the order given above (logically obvious); the order of the variable definitions within a "define" attribute is significant, however, so that a variable can be used in the same define attribute in later assignments.
If there is no element that can be used to carry the TAL attributes, special TAL tags can also be used; in this case the prefix is tal:
optional. Example:
<tal:if condition="context/itemlist">
...
</tal:if>
The code within the <tal:if>
element is used if, for example, the variable “itemlist” defined in the context (whatever that means for the application server used, for example an object) is true , i.e. contains at least one element in the case of a list. The identifier after the colon is arbitrary; it just has to be the same for the opening and closing day.
use
TAL / TALES / METAL are used by the following projects:
- Zope web application server
- Roundup (bug tracker)
Other implementations
In addition to the original Zope implementation, there are (without claiming to be exhaustive) the following:
Java
- JPT: Java Page Templates ( christophermrossi.com )
- JavaZPT ( javazpt.sourceforge.net )
JavaScript
- Distal ( http://code.google.com/p/distal )
- DomTal ( https://github.com/drslump/DomTal )
Pearl
- PETAL, the Perl Template Attribute Language ( search.cpan.org )
- Template-TAL ( search.cpan.org )
PHP
- PHPTAL, the PHP incarnation of TAL ( http://phptal.org/ )
python
- SimpleTAL ( owlfish.com TAL guide )
- OpenTAL ( savannah.nongnu.org )
- ZPT ( zpt.sourceforge.net - a standalone version of the Zope Page Templates )
- Chameleon ( https://chameleon.readthedocs.io )
XSL
- XSLTAL, transforms TAL into XSLT using XSL ( http://wiki.flux-cms.org/display/FLX/Templates+XSLTAL )
See also
literature
- Erik Möller: Template TALent - web templates with TAL, TALES and METAL (practice, TAL templates for Zope X3, Template Attribute Language, TAL, TALES, METAL, content management system, CMS, PHPTAL, PETAL, JavaZPT) . In: c't , 3/2005, p. 194
Web links
- Specification of version 1.4
- Zope Page Templates Reference (in the Zope Book)