Welcome to MyPresta.eu – Your reliable partner in the e-commerce world. Find innovative modules that will take your business to a new level.
From legacy {assign} tags to modern {{ output }} blocks. A definitive guide for developers transitioning from the Classic theme to the Symfony-powered future.
As PrestaShop continues its strategic migration towards the Symfony framework, the ecosystem stands at a crossroads. For over a decade, Smarty has been the reliable workhorse rendering the front office of countless e-commerce stores. However, with the release of PrestaShop 9 and the development of the new "Hummingbird" reference theme, Twig is cementing its place as the standard for the future.
For module creators and theme developers, understanding the transition from Smarty to Twig is no longer optional—it is essential. This guide provides an extensive comparison of the two engines using modern Tailwind CSS for context.
Twig compiles templates into optimized native PHP code, offering faster execution times than Smarty in most scenarios.
Twig’s design encourages a stricter separation of logic and presentation (MVC), reducing the risk of PHP code injection.
Since the Back Office uses Symfony, using Twig (Symfony’s default engine) unifies the development experience.
Most fundamental operation. Twig uses {{ }} exclusively for printing output.
<h1 class="text-3xl font-bold"> {$product.name} </h1> <h1 class="text-3xl font-bold"> {{ product.name }} </h1> Twig treats modifiers as functions with parentheses () .
<p> {$desc|default:'No description.'} </p> <p> {{ desc|default('No description.') }} </p> Twig uses {% set %} which is much cleaner than Smarty's assign tag.
{assign var='color' value='bg-red-500'} <span class="{$color}">Sale</span> {% set color = 'bg-red-500' %} <span class="{{ color }}">Sale</span> Note the lack of $ prefix for variables inside Twig's logic tags.
{if $qty > 0} <span>In Stock</span> {else} <span>Out of Stock</span> {/if} {% if qty > 0 %} <span>In Stock</span> {% else %} <span>Out of Stock</span> {% endif %} Twig uses Python-like for item in list syntax.
{foreach from=$products item=p} <div>{$p.name}</div> {/foreach} {% for p in products %} <div>{{ p.name }}</div> {% endfor %} The {l} tag is replaced by the trans filter.
{l s='Add to cart' d='Shop.Theme.Actions'} {{ 'Add to cart'|trans({}, 'Shop.Theme.Actions') }} Extending base templates is syntactically clearer in Twig.
{extends file='page.tpl'} {block name='content'} <h1>Hi</h1> {/block} {% extends 'page.html.twig' %} {% block content %} <h1>Hi</h1> {% endblock %} Smarty variables often leaked into the global scope, making them accidentally available in included files. Twig is strictly scoped. If you don't pass a variable explicitly to a partial or included template, it simply won't exist. This often leads to "Variable does not exist" errors during migration.
Legacy developers often used {php} tags in Smarty for quick logic fixes or database queries directly in the view. Twig strictly forbids PHP execution. All logic must be moved to the Controller or a Twig Extension, enforcing a strict MVC pattern.
Smarty came with a massive library of modifiers (e.g., regex_replace ). Twig has fewer built-in filters. Complex string manipulations that worked in Smarty might require you to write custom Twig Extensions or process the data in PHP before sending it to the view.
While PrestaShop provides a compatibility layer, rendering a module that uses Smarty hooks inside a Twig-based page can sometimes lead to context loss. Variables expected by the Smarty module might not be passed correctly from the Twig parent, leading to empty content blocks.
Dual Maintenance: For the next few years, high-quality modules must ship with both Smarty templates (for Classic themes) and Twig templates (for modern/custom themes).
Logic Migration: Smarty allowed "lazy" PHP logic in templates. Twig is restrictive. Logic must move to PHP classes/controllers.
Refactoring Costs: Agencies with libraries of custom modules will face a significant refactoring burden. The sooner this starts, the better.
Artykuł napisany przez Milosza Myszczuka, eksperta PrestaShop i oficjalnego moderatora społeczności PrestaShop. CEO i założyciel agencji interaktywnej VEKIA. Dowiedz się więcej.
If you like this article, support our work!

Automatic National Bank of Ukraine (NBU) currency rates integrator. The module guarantees precise pr...
19.99 €

Automatic Bank of Spain (Banco de España - BdE) currency rates integrator. The module guarant...
19.99 €

The Currency Exchange Module offers unparalleled flexibility in managing international sales. Regard...
19.99 €

Integrate your store with the Central Bank of the Republic of Turkey (TCMB) using this module. It au...
19.99 €