Templates overview
This page is for designers who start writing templates. Exponential's templates are text files ending in .tpl,
written in its own template language (TPL), which mixes HTML with tags in braces: {$node.name|wash},
{foreach ...}, {include ...}. This page is the map; each section links to the details.
Contents
- What a template does
- The kinds of templates in a design
- The language in one screen
- Where templates get their data
- Reading path
What a template does
A template turns data (a node, a list, settings) into HTML. It has no access to the database or the file system except through fetch functions and operators the kernel and extensions provide, which keeps templates safe to hand to designers. Templates are compiled into PHP the first time they run and cached (Template compilation and cache).
The kinds of templates in a design
| Kind | Example path | Called by |
|---|---|---|
| Pagelayout | pagelayout.tpl | the kernel, around every page (The pagelayout) |
| Node view templates | node/view/full.tpl, node/view/line.tpl | content views, node_view_gui (View modes) |
| Override templates | override/templates/full/article.tpl | override.ini rules (Override basics) |
| Datatype templates | content/datatype/view/ezstring.tpl | attribute_view_gui (Datatype view templates) |
| Module templates | user/login.tpl, content/search.tpl | module views |
| Parts | pagelayout/header.tpl, parts/teaser.tpl | {include} from other templates |
| Layout block templates | explayouts/block/list.tpl | the layouts engine (Layouts for designers) |
The language in one screen
{* a comment *}
{def $children = fetch( 'content', 'list', hash( 'parent_node_id', $node.node_id,
'sort_by', $node.sort_array,
'limit', 10 ) )}
if $children|count
<ul class="children">
foreach $children as $child
<li><a href=$child.url_alias|ezurl>$child.name|wash</a></li>
/foreach
</ul>
else
<p>'Nothing here yet.'|i18n( 'design/mytheme' )</p>
/if
undef $children{def},{if},{foreach},{include}are functions (Function reference).|wash,|ezurl,|count,|i18nare operators;fetch(),hash()too, called with parentheses (Operators overview).$node.namereads an attribute of an object (Attributes and dot notation).
Where templates get their data
- Variables the caller sets: a full view gets
$node; a datatype template gets$attribute; the pagelayout gets$module_resultand$site(Pagelayout variables). - Fetch functions:
fetch( 'content', 'list', ... ),fetch( 'user', 'current_user' ),fetch( 'explayouts', ... )(Fetch basics). - Settings:
ezini( 'Section', 'Setting', 'file.ini' )(The ezini operator). - The request:
ezhttp()for GET and POST values, carefully (The ezhttp operator).
Reading path
- TPL syntax basics, Variables and def, If and conditions, Foreach loops, Include.
- Wash and escaping, URL operators, The i18n operator.
- Fetch basics, Nodes, objects and attributes, View modes.
- Override basics, Override match keys.
- Template style guide, Common template mistakes.
Related pages
- Operator reference
- Function reference
- Designers: start here
- 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.