Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,075 of 9,075 pages
About the help in other languages
All help pages

What the template language is

The Exponential template language (eZ TPL, ezpl) in one page - a Smarty-like language for .tpl files, where it is used (designs, module views, mail, PDF), the parts of the engine in lib/eztemplate, and what it does…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/template-language/what-the-template-language-is.md

On this page

What the template language is

Every page Exponential renders, every mail it sends from a template and every PDF export is written in its own template language. In the code it is the eZTemplate library in lib/eztemplate/, the files end in .tpl, and people call it eZ TPL or ezpl. In these pages it is "the template language".

It looks like Smarty: tags in curly braces, variables with $, values piped through |. Underneath it was built for a content management system, so it has a large set of registered operators and functions, it reads PHP objects through an attribute protocol, it fetches content itself with fetch(), and it chooses which template to use through the override system instead of template inheritance.

Contents

  1. A first look
  2. Where templates are used
  3. The parts of the engine
  4. Beyond Smarty, out of the box
  5. How the examples in this section were made
  6. Related pages

A first look

A template mixes text with tags. This one fetches the "Fit & Healthy" front page of a development installation (node 89), prints its name escaped for HTML and lists its first four children:

{def $site = fetch( 'content', 'node', hash( 'node_id', 89 ) )}
<h2>{$site.name|wash}</h2>
<p>{$site.children_count} pages below, class {$site.class_identifier}</p>
<ul>
{foreach $site.children as $child max 4}
  <li>{$child.name|wash} ({$child.class_identifier})</li>
{/foreach}
</ul>

Output:

<h2>Fit &amp; Healthy</h2>
<p>16 pages below, class ng_frontpage</p>
<ul>  <li>Fitness (ng_landing_page)</li>  <li>Healthy eating (ng_landing_page)</li>  <li>Recipes (ng_category)</li>  <li>Running (ng_topic)</li></ul>

Four kinds of things appear in it:

  • Functions are tags with a name: {def ...}, {foreach ...}{/foreach}. They control the template: they create variables, loop, branch, include other templates.
  • Variables start with $: $site, $child.
  • Attributes follow a dot: $site.name, $child.class_identifier. The value can be an array or a PHP object.
  • Operators compute a value: fetch( ... ), hash( ... ), |wash. They are written either as a call or after a pipe.

Where templates are used

WhereHow a template is reachedExample in the code
Designs (the site and the admin)design: URIs resolved through the design bases and the override systemkernel/common/eztemplatedesignresource.php
Module viewsa view's PHP sets variables and fetches a template, the result becomes $module_result.content in the pagelayoutkernel/content/view.php
Mailthe same engine renders the mail textkernel/user/ezuseroperationcollection.php fetches design:user/registrationinfo.tpl
Notificationshandlers render their digest and subtree mailskernel/classes/notification/handler/ezsubtree/ezsubtreehandler.php
PDF exportthe pdf operator and the content_pdf_gui and attribute_pdf_gui functionslib/ezpdf/classes/ezpdf.php, kernel/content/pdf.php

The same engine object serves all of them: eZTemplate::factory() (in lib/eztemplate/classes/eztemplate.php) creates it once per request, loads the operator and function lists, and registers the design resource.

The parts of the engine

PartFileWhat it does
The enginelib/eztemplate/classes/eztemplate.phpvariables and namespaces, resources, registered operators and functions, processing
Parserlib/eztemplate/classes/eztemplatemultipassparser.php, eztemplateelementparser.phpsplits the text into text, tags and comments, removes whitespace around tags, builds the node tree
Node treeeztemplateroot.php, eztemplatetextelement.php, eztemplatevariableelement.php, eztemplatefunctionelement.php, eztemplateoperatorelement.phpthe parsed template in memory
Compilerlib/eztemplate/classes/eztemplatecompiler.php, eztemplateoptimizer.php, eztemplatenodetool.phpturns the tree into PHP code once, so later requests only include a PHP file
Resourceseztemplatefileresource.php; kernel/common/eztemplatedesignresource.phpfile: reads a path; design: searches the design bases and applies overrides
Tree cachelib/eztemplate/classes/eztemplatetreecache.phpkeeps parsed trees ([TemplateSettings] NodeTreeCaching)
Operatorslib/eztemplate/classes/eztemplate*operator.php, kernel/common/, extensionsone PHP class per family, listed in an eztemplateautoload.php
Functionslib/eztemplate/classes/eztemplate*function.php, kernel/common/ezobjectforwarder.phpif, foreach, def, include, cache-block, the *_view_gui functions

The library has no dependency on the content model: it only knows text, values and objects that answer attributes(), hasAttribute() and attribute(). The kernel adds the content-aware parts: the design resource, the fetch functions of each module, and the view functions such as node_view_gui.

Beyond Smarty, out of the box

What the language offers without any extension installed, with the page that covers it:

  • Several hundred registered operators. On the site siteaccess the engine registers 395 operators and 48 functions (counted by loading every entry of the operator and function lists). The template library alone brings arithmetic, arrays, strings, the PHP string functions, logic, types, locale, digests and roles.
  • Data access in the template. fetch( 'content', 'list', hash( ... ) ) reads content with filters, sorting and permissions, and every module can offer its own fetch functions.
  • Objects with attributes. A node is a PHP object, yet $node.parent.name or $node.data_map.title.content reads like an array. See Attribute access.
  • The override system picks a template by class, section, node, view mode and more, instead of templates extending each other (Override basics).
  • Namespaces keep the variables of included templates apart (Namespaces).
  • A compiler that writes PHP for each template and cache blocks that store finished HTML (Template compilation and cache).
  • Translation and localization built in: i18n, l10n, datetime.

A second example uses several of these on one article (node 90, "Privacy Policy"):

{def $article = fetch( 'content', 'node', hash( 'node_id', 90 ) )}
Fields: {$article.data_map|count}
Title field: {$article.data_map.title.content|wash}
Parent: {$article.parent.name|wash}
Path: {foreach $article.path as $step}{$step.name|wash} / {/foreach}{$article.name|wash}
URL: {$article.url_alias|ezurl( 'no', 'relative' )}
Can the visitor read it: {if $article.can_read}yes{else}no{/if}

Output:

Fields: 18
Title field: Privacy Policy
Parent: Fit &amp; Healthy
Path: Websites / Fit &amp; Healthy / Privacy Policy
URL: /privacy-policy
Can the visitor read it: yes

How the examples in this section were made

Every example in the template language pages was rendered on a development installation, by the real engine against real content, and the output under it is what the engine printed. The examples are kept outside the design tree and read with the file: resource; compiling and template caching were switched off for those runs, and each example was rendered a second time through the compiler to check that both give the same output. Where an example shows an error on purpose, the page also shows what the engine logged.

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.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x