Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Template Attribute Language

From Wikipedia, the free encyclopedia
This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages)
This articledoes notcite anysources. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged andremoved.
Find sources: "Template Attribute Language" – news ·newspapers ·books ·scholar ·JSTOR
(January 2012) (Learn how and when to remove this message)
The topic of this articlemay not meet Wikipedia'sgeneral notability guideline. Please help to demonstrate the notability of the topic by citingreliable secondary sources that areindependent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to bemerged,redirected, ordeleted.
Find sources: "Template Attribute Language" – news ·newspapers ·books ·scholar ·JSTOR
(January 2012) (Learn how and when to remove this message)
(Learn how and when to remove this message)

TheTemplate Attribute Language (TAL) is a templating language used to generate dynamicHTML andXML 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 forZope but is used in otherPython-based projects as well.

Attributes

[edit]

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

define
creates local variables, valid in theelement 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 usingtal:attributes="name name; id name" the name and id attributes of an input field could be set to the value of thevariable "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:ifcondition="context/itemlist">...</tal:if>

would cause the code inside thetal: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 atrue 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

[edit]

The Macro Expansion Template Attribute Language (METAL) complements TAL, providingmacros which allow the reuse of code across template files. Both were created forZope but are used in otherPython 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 haveslots; when using a macro, variational content can be specified for a slot.

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

METAL attributes

[edit]

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
sinceZope v3: extends a macro, comparable tosubclassing, 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 withRoundup in mind):

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

Usage

[edit]

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

Other implementations

[edit]

Besides the originalZope implementation, there are (not exhaustive):

Python

[edit]

C#

[edit]
  • SharpTAL

Go (Golang)

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

JavaScript

[edit]

Java

[edit]
  • JPT:Java Page Templates
  • JavaZPT
  • ZPT-Java

Perl

[edit]
  • PETAL, thePerl Template Attribute Language
  • Template-TAL

Raku

[edit]
  • Flower, aRaku implementation of TAL, with some Petal and PHPTAL extensions.

PHP

[edit]
  • PHPTAL
  • Twital
  • Biscuit
  • zTAL

XSL

[edit]

Common Lisp

[edit]
  • TALCL: A library that implements the TAL template language forcommon lisp

Similar implementations

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

References

[edit]

External links

[edit]
Retrieved from "https://en.wikipedia.org/w/index.php?title=Template_Attribute_Language&oldid=1161362706"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp