The template language
The template language of Exponential (files ending in .tpl) mixes text, usually HTML, with template code between curly brackets. The template system reads everything between { and } as code; everything else is sent as it is.
<h1>{$node.name|wash}</h1>
{if $node.children_count|gt( 0 )}
<p>{$node.children_count} pages below this one.</p>
{/if}
Inside the brackets you find four kinds of code:
- Variables, written with a dollar sign: $node, $node.name. See Variable usage and Variable types.
- Operators, which take a value and return one, chained with a pipe: $node.name|wash, $count|gt( 0 ). See Functions and operators.
- Functions, which do something and often have a closing tag: {if}...{/if}, {foreach}, {include}, {def}. See Control structures.
- Comments: {* ... *}. See Comments.
Variable names are case sensitive: $Title and $title are two variables.
Curly brackets in the output
Because { starts template code, text that contains curly brackets, such as JavaScript or CSS, must be put inside {literal}; the template system does not read what is between {literal} and {/literal}:
{literal}
<script>
function focusSearch() { document.getElementById( 'search' ).focus(); }
</script>
{/literal}
A single bracket is written with the functions {ldelim} and {rdelim}, which print { and }. Inside a quoted string, a closing bracket is escaped with a backslash: {'{ inside \}'} prints { inside }.
Better still, keep scripts and styles in files of the design and load them with the ezjscore functions or the design settings, as the pagelayout of the standard design does (see The pagelayout).
In this section
- Comments
- Variable types
- Variable usage
- Array and object inspection
- Control structures
- Functions and operators
The language in full depth, from its lexical structure to the compiler, is in the template language manual. Developers who know Smarty or Twig can write templates in those languages instead; see Template engines.
In this section
- Variable types Value types of the Exponential 6 template language: numbers, strings, booleans, arrays made with array() and hash(), and objects.
- Variable usage Variables in Exponential 6 templates: def, set and undef, reading arrays and object attributes, missing values, and the persistent variable for the pagelayout.
- Array and object inspection Inspecting variables in Exponential 6 templates with the attribute and dump operators, and the attribute references of nodes and objects.
- Control structures Control structures of the Exponential 6 template language: if, switch, foreach, for, while and do, with tested examples.
- Functions and operators Template functions and template operators in Exponential 6: how they are called, the most used ones, the generated references and your own operators.
Contributors
- Balazs Halasy
- Geir Arne Waaler
- Kristof Coomans Commenter
- Graham Brookins Updated Maintainer
Comments (1 historical)
Written by readers of the earlier documentation sites, kept as they were.
Debug
Kristof Coomans ·
When you're going to change any templates, you're encouraged to put on debug output, so you'll be warned with a parse error when you made a mistake against the template syntax.
See http://ez.no/doc/ez_publish/techn...uration_files/site_ini/debugsettings
and
http://ez.no/doc/ez_publish/techn...tion_files/site_ini/templatesettings