What is TAL?
PLONE SYMPOSIUM EAST 2011
* Zope Templating Language
* Allow for dynamic content in HTML
* Does not render in the site
TAL Syntax
PLONE SYMPOSIUM EAST 2011
<div tal:content=”context/Title”></div>
<tal:title content=”context/Title” />
Use an HTML tag or <tal:whatever...
TAL Syntax
PLONE SYMPOSIUM EAST 2011
<a tal:attributes=”href url;
class linkClass”>
* separate multiple declarations with a semicolon
* align variables/attributes on the left
TAL Syntax
PLONE SYMPOSIUM EAST 2011
<div tal:condition=”python:phone and fax”>
Python expressions allow us to put Python code
directly in the template. This is not meant for
long, complex expressions.
TAL Syntax
PLONE SYMPOSIUM EAST 2011
<a tal:attributes=
”href string:${item/url}/folder”>
With string expressions, we can add static text to
dynamic content or combine multiple variables
TAL Commands
PLONE SYMPOSIUM EAST 2011
* define
* condition
* repeat
* content/replace
* attributes
* omit-tag
tal:content
PLONE SYMPOSIUM EAST 2011
* determines what content will display inside a
tag
* any content inside the tag in the template will
not display in the site
<span tal:content=”title”>The Title</span>
tal:content
PLONE SYMPOSIUM EAST 2011
use ‘structure’ for content with HTML code,
so the code is not rendered as text
<tal:body content=”structure context/getText” />
tal:replace
PLONE SYMPOSIUM EAST 2011
* determines what content will display in place
of a tag
* the tag will not display in the site
<span tal:replace=”title”>The Title</span>
tal:replace
PLONE SYMPOSIUM EAST 2011
* replacing an element with ‘nothing’ will not
render in the site
* good for commenting out parts of the code
<div tal:replace=”nothing”>
This is a comment
</div>
tal:attributes
PLONE SYMPOSIUM EAST 2011
allows you to set a dynamic value to an attribute
(href, src, class, etc)
<a href=”#”
tal:content=”crumb/Title”
tal:attributes=”href crumb/absolute_url”></a>
tal:omit-tag
PLONE SYMPOSIUM EAST 2011
* similar to condition, evaluates an expression
* if true, the wrapping tag is omitted, and only
the content is displayed
* if false, the tag displays
* omit-tag=”” will also omit the tag
Macros
PLONE SYMPOSIUM EAST 2011
The Macro Expansion Template Attribute
Language (METAL) allows us to create macros
within our page templates, which saves us from
repeating code.
* define-macro / use-macro
* define-slot / fill-slot