BookRags.com Literature Guides Literature
Guides
Criticism & Essays Criticism &
Essays
Questions & Answers Questions &
Answers
Lesson Plans Lesson
Plans
My Bibliography Periodic Table U.S. Presidents Shakespeare Sonnet Shake-Up
Research Anything:        
History | Encyclopedias | Films | News | Create a Bibliography | More... Login | Register | Help
Not What You Meant?  There are 22 definitions for TAL.

Template Attribute Language

Print-Friendly
About 2 pages (612 words)

Bookmark and Share Questions on this topic? Just ask!

The Template Attribute Language (TAL) is a templating language aimed to generate HTML and XML pages. Its main goal is to simplify the collaboration of programmers and designers by templates being proper HTML (or XML, respectively) which can be worked on using common design tools. TAL was created for Zope but is used in other Python-based projects as well.

Contents

Overview

TAL Templates are often made from result pages with the variable content being replaced by special attributes; e.g.,

<h1 tal:content="string:Some altogether different headline">
The headline visible to the designer
</h1>

would be treated by a common HTML design tool as

<h1>
The headline visible to the designer
</h1>

while the application server, evaluating the tal:content attribute, would yield

<h1>
Some altogether different headline
</h1>

Of course, string literals are not the most common nor the most useful use case; the syntax of the possible attribute values is property of the TAL Expression Syntax (TALES) language. In the Python-based implementations, it is e.g. 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 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 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.

Usage

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

Other implementations

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

Python

Java

Perl

PHP

XSL

External links

View More Summaries on Template Attribute Language
 
Ask any question on Template Attribute Language and get it answered FAST!
Answer questions in BookRags Q&A and earn points toward
discounted or even FREE Study Guides and other BookRags products!
Learn more about BookRags Q&A
Copyrights
Template Attribute Language from Wíkipedia. ©2006 by Wíkipedia. Licensed under the GNU Free Documentation License. View a list of authors or edit this article.

Article Navigation
Join BookRagslearn moreJoin BookRags




About BookRags | Customer Service | Report an Error | Terms of Use | Privacy Policy