TPL syntax basics
This page is for designers who read or write templates. It lists the rules of the template language once, so the other pages can be short.
Contents
Text and tags
Everything outside braces is printed as it is. Everything inside { } is a template tag:
| Tag | Meaning |
|---|---|
{$variable} | print a value |
{$value|operator} | print a value passed through operators |
{function param=value} ... {/function} | a function with a body |
{function param=value} | a function without a body |
{* ... *} | a comment, never printed |
Values
| Kind | Written as |
|---|---|
| string | 'single' or "double" quotes |
| integer, float | 42, 3.5 |
| boolean | true(), false() (operators, written with parentheses) |
| array | array( 'a', 'b', 'c' ) |
| hash | hash( 'key', 'value', 'other', 2 ) |
| test for nothing | $value|null (true when the value is null), is_set( $value ) |
Variables
Variables start with $. They are created with {def}, changed with {set}, removed with {undef}
(Variables and def). Attributes of objects and keys of hashes are read with a dot:
$node.name, $node.data_map.title, $hash.key; array items with a number: $list.0
(Attributes and dot notation).
Operators
Two equivalent ways to call an operator:
$text|upcase {* pipe: the value on the left is the input *}
upcase( $text ) {* call *}
$text|shorten( 80 ) {* pipe with parameters *}
concat( 'a', $b, 'c' ) {* call with several values *}Operators can be chained: {$text|strip_tags|shorten( 120 )|wash}. Comparison and arithmetic are operators too:
eq( $a, 1 ), gt( $count, 10 ), sum( $a, 2 ) (Operators overview).
Functions
Functions control the template: {if}, {foreach}, {def}, {include}, {cache-block}. Parameters are
name=value pairs or, for some functions, a fixed syntax:
include uri='design:parts/teaser.tpl' node=$child
foreach $items as $item ... /foreachSee the Function reference.
Comments
{* A comment: may span several lines, never reaches the browser. *}Use template comments, not HTML comments (<!-- -->), for notes about the template: HTML comments are sent to every
visitor.
Braces in the output
A literal { or } in the output (CSS or JavaScript inside a template, which designs avoid anyway) is written as
{ldelim} and {rdelim}, or the text is wrapped in {literal} ... {/literal} (Literal and delimiters).
Related pages
- Templates overview
- Variables and def
- Operators overview
- 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.