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 three template engines compared

This guide is for site builders and template developers who choose between the template engines of Exponential: Exponential templates (.tpl), Smarty templates (.stpl) and Twig templates (.twig, .html.twig). All three…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/guides/template-engines.md

On this page

The three template engines compared

This guide is for site builders and template developers who choose between the template engines of Exponential: Exponential templates (.tpl), Smarty templates (.stpl) and Twig templates (.twig, .html.twig). All three run in the same template system, see the same variables, can call every operator, fetch function and template function, and can be mixed in one design and one page. What differs is the language, its tools and who already knows it.

At a glance

.tpl.stpl.twig
LanguageExponential's own template languageSmarty 5Twig 3
Librarythe kernelSmarty 5 (smarty/smarty, [SmartySettings] LibraryPath)Twig 3 (twig/twig on PHP 8.1 and later, se7enxweb/twig on 7.4 and 8.0, both through se7enxweb/exponential-php-floor; [TwigSettings] LibraryPath)
Settingstemplate.inismarty.initwig.ini
Compiled toPHP (<cache>/template/compiled)PHP (<cache>/smarty/compile-secure)PHP classes (<cache>/twig/compile-secure)
Operatorsby nameas modifiers; exp_<name> where Smarty has the nameas filters and functions; exp_<name> where Twig has the name
Template functions{attribute_view_gui ...}{attribute_view_gui ...} (same parameters){{ attribute_view_gui({...}) }}
Include{include uri=...}{expinclude uri=...}{% expinclude uri=... %}
Cache block{cache-block}{expcacheblock}{% expcacheblock %}
Sandboxthe template system's rulesSmarty's security policy, on by defaultTwig's sandbox, on by default
Escapingwashwash (no auto escaping)wash (no auto escaping by default)
Inheritance, macrosno{extends}, {block}, {function}, as smarty.ini allows them{% extends %}, {% block %}, {% macro %}
Debug baryesyes, with the .stpl fileyes, with the .twig file
Convertersto and from both othersto and from both othersto and from both others

Which to choose

  • .tpl for an existing design and for developers who know Exponential: every example, every shipped design and every extension's templates are .tpl, and nothing has to be installed.
  • .stpl for a team that knows Smarty, or a design that comes from a Smarty project.
  • .twig for a team that knows Twig from Symfony, Drupal or Craft, or templates shared with such a project (.html.twig). The editors and tools that support Twig work with the files as they are.

Speed does not decide it: cached pages never reach a template engine, and uncached pages render within a small margin of each other. Measured on a development installation, a converted design rendered uncached pages as .twig at 0.83 to 0.98 times the time of the .tpl design and 0.90 to 1.19 times the .stpl design; with the debug output on, .twig and .stpl pages took 0.037 to 0.044 s and .tpl pages 0.059 to 0.110 s. Every number with its conditions, the profile of a request and how to measure your own: Speed of the three template engines (Twig performance, Smarty performance).

Reading one when you know another

Templates side by side puts the same template in all three languages, row by row, every row rendered with identical output. For Twig written the Twig way (inheritance, embed, macros, tests) see Writing Twig-native templates; for complete starting points, Twig recipes.

Mixing them

Each template of a design can be of any engine. The design resource finds x.tpl, x.stpl or x.twig as the override rules and the design order say, and every engine includes the others through it:

{include uri='design:parts/menu.twig'}                 .tpl includes a .twig
{expinclude uri='design:parts/menu.tpl'}               .stpl includes a .tpl (or what an override rule names)
{% expinclude uri='design:parts/menu.stpl' %}          .twig includes a .stpl

Variables cross with the include (its parameters, the shared namespace). A design can therefore move one template at a time: convert the pagelayout, keep the rest, and convert more when it suits.

Converting between them

Six commands convert in every direction, and exp:template:convert takes --from-engine and --to-engine:

./console exp:template:engines
./console exp:template:convert:tpl-to-twig --from=<design> --to=<design>_twig
./console exp:template:convert:twig-to-stpl --from=<design>_twig --to=<design>_stpl

Every converted file is checked before it is written and carries a marker, so a second run replaces only what was converted and not changed since; see Converting templates between template engines. exp:template:check checks the syntax of all three (Checking template syntax).

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