Learning the template language
Exponential renders every page, mail and PDF with its own template language, known as eZ TPL: brace tags like Smarty's, with operators and functions for content objects, a fetch API to read data, an override system to choose templates, and a compiler that turns templates into PHP (The template language). Designers and developers both need it. This page gives you a study plan.
Contents
- The five constructs to learn first
- Your first template
- A reading order
- Drills
- Mistakes learners make
- If you know Smarty
The five constructs to learn first
| Construct | Example | Meaning |
|---|---|---|
| Output with escaping | {$node.name|wash} | Print a value; wash escapes HTML. Use it on anything a user typed |
| Variables | {def $items = ...}, {set $items = ...}, {undef $items} | Declare once, change later, free |
| Data | fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id, 'limit', 5 ) ) | Read content; hash builds named values |
| Loops and conditions | {foreach $items as $child}...{/foreach}, {if $node.depth|gt( 2 )}...{/if} | Operators are written as pipes: gt, lt, eq, and, or, not |
| Showing content | {attribute_view_gui attribute=$node.data_map.title}, {node_view_gui content_node=$child view='line'} | Let each attribute and node use its own template |
Source: Templates and design, part 6.
Comments are written {* ... *}. Links use ezurl, written without quotes in an attribute:
<a href={$child.url_alias|ezurl}>.
Your first template
The templates guide gives a small template to try in an override (it lists the children of the current item's parent, ten at most):
<h1>{$node.name|wash}</h1>
{def $siblings = fetch( 'content', 'list', hash( 'parent_node_id', $node.parent_node_id, 'limit', 10 ) )}
<ul>
{foreach $siblings as $sibling}
<li><a href={$sibling.url_alias|ezurl}>{$sibling.name|wash}</a></li>
{/foreach}
</ul>
{undef $siblings}Expected: the heading followed by a list of links. Put it in the override of project 3, then explain each line in your study journal.
A reading order
Start task-oriented, then go deep:
- Templates overview and TPL syntax basics, the gentle introduction.
- Templates and design, parts 1 to 6: how a template is found, overrides, syntax checks.
- What the template language is.
- Values and literals and Variables in depth.
- Control structures reference.
- The object model in templates and Data map and content.
- Errors and debugging.
- Template resources and overrides and Template caches.
- The operator reference as you need it: Template operators.
The trainers' Developers course has a whole module on the language, module 2, with exercises and quizzes.
Drills
Short exercises, each on your study site, in an override you can remove afterwards:
- Print the name and the node number of the current item.
- List the first five children of the item with links. Then show "No items" when there are none.
- Show the title attribute with
attribute_view_gui, then print$node.data_map.title.contentand compare. - Use
{delimiter}to put commas between names in a loop. - Put a deliberate error in a template (an unknown operator), check it with
php bin/php/eztemplatecheck.php, then read what the engine logs (Errors and debugging).
Mistakes learners make
| Mistake | Result | Fix |
|---|---|---|
Forgetting wash | Text with < or quotes can break the page or open a security hole | |wash on every value from content or visitors |
{def} the same variable twice | A warning | {def} once, {set} afterwards |
Editing design/standard/templates/ | Lost at the next upgrade | An override in your own design |
Expecting arithmetic like $a + 1 | Does not work | Operators such as sum; see the differences from Smarty |
| A new template path without clearing caches | The old template is used | Clear the override and template caches once |
If you know Smarty
Read Smarty and the template language side by side and the differences in depth: no infix arithmetic or comparison, no PHP in templates, no automatic escaping, and overrides instead of inheritance.
Related pages
- Project 3: a template override
- Learning path: designer
- Learning path: developer
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.