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

The view layer: the template language beside Twig and Blade

The Exponential template language for developers who know Twig, Blade, Jinja or ERB - syntax side by side, operators instead of infix symbols, no automatic escaping, fetch in the template, the pagelayout instead of…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/web-framework-developers/templates-vs-twig-and-blade.md

On this page

The view layer: the template language beside Twig and Blade

This page is for developers who write Twig, Blade, Jinja or ERB templates. Exponential renders HTML with its own template language: .tpl files that eZTemplate (lib/eztemplate/classes/eztemplate.php) compiles to PHP. It looks like Smarty at first sight; Moving a template from Smarty and What the template language is cover it in depth. Here are the differences that matter most when you come from another framework.

Contents

  1. Syntax side by side
  2. Five differences that bite
  3. Layouts
  4. Includes, partials and components
  5. Extending the language
  6. Compilation and caches
  7. Can I use Twig instead?

Syntax side by side

TaskTwigBladeExponential template language
Print, escaped{{ title }}{{ $title }}{$title|wash}
Print raw{{ html|raw }}{!! $html !!}{$html}
Variable{% set n = 3 %}@php($n = 3){def $n = 3} (new), {set $n = 4} (change)
Condition{% if a > 1 %}@if($a > 1){if $a|gt( 1 )} ... {/if}
Loop{% for p in pages %}@foreach($pages as $p){foreach $pages as $p} ... {/foreach}
Attributepage.parent.name$page->parent->name$page.parent.name
Filter or helpername|upperstrtoupper($name)$name|upcase
Arithmetica + b$a + $bsum( $a, $b ) or $a|sum( $b )
Translation'Save'|trans__('Save')'Save'|i18n( 'extension/expdemo' )
URLpath( 'item', {id: 42} )route( 'item', 42 )'expdemo/item/42'|ezurl
Comment{# ... #}{{-- ... --}}{* ... *}

Five differences that bite

From Smarty and the template language: the differences in depth:

  1. No automatic escaping. Output is never escaped by the engine; write |wash on everything that comes from content, URLs or request parameters. Rendered rich text is printed through its view template (attribute_view_gui) and must not be washed again.
  2. No infix arithmetic or comparison. {if $a > 1} does not do what it says; use gt, eq, and, sum and the other operators.
  3. Unknown operators pass their input through with a logged error instead of failing the page, so a typo can print raw data. Watch the debug output while developing.
  4. def and set are strict: def creates, set changes; misuse writes a warning.
  5. No PHP in templates. Logic goes into operators, fetch functions and the view.

Layouts

There is no {% extends %} or @extends. The siteaccess's pagelayout (pagelayout.tpl) is the base layout of every page: the view renders its own template, and the pagelayout prints it with {$module_result.content} (Responses). Where Twig would override a block of a parent template, Exponential replaces a whole template by an override chosen by conditions such as the content class, the node or the view mode (Template resolution).

Includes, partials and components

NeedUse
A partial{include uri='design:parts/menu.tpl' title=$node.name}; extra parameters become variables in the included template
Render a content item in a view mode (a "component" for content){node_view_gui content_node=$child view='line'} picks node/view/line.tpl and its overrides
Render one field{attribute_view_gui attribute=$node.data_map.title} uses the datatype's view template
Keep variables apartnamespaces, set by the view functions (Namespaces)

Extending the language

Twig or BladeExponential
Twig filter or function, Blade directivea template operator: a PHP class registered in extension/<ext>/autoloads/eztemplateautoload.php (Template operators)
Twig taga template function (Custom template functions)
View composer or a Twig global from a servicea fetch function (fetch( 'expdemo', 'stats', hash() )) (Getting data into templates)

Compilation and caches

Templates are compiled to PHP files under the cache directory and rebuilt when the source changes (Template compilation). Content views are additionally kept in the view cache, and {cache-block} stores finished HTML fragments (Template caches, Caching). When a template "does not change", the cause is almost always one of these caches.

Can I use Twig instead?

Not in the legacy kernel alone. Twig is available when the kernel runs inside the Symfony platform through the legacy bridge: the public site can render with Twig while editors keep the legacy administration, and the ngsymfonytools extension lets a .tpl template include a Twig template or render a Symfony controller (Symfony legacy bridge, Platform site bundles).

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