Unleash the Full Potential of Your PrestaShop Store

Welcome to MyPresta.eu – Your reliable partner in the e-commerce world. Find innovative modules that will take your business to a new level.

Smarty vs. Twig in PrestaShop

14.01.2026
Migration Guide PrestaShop 9 & Beyond

Smarty vs. Twig:
The Great Template Swap

From legacy {assign} tags to modern {{ output }} blocks. A definitive guide for developers transitioning from the Classic theme to the Symfony-powered future.

Smarty vs. Twig in PrestaShop 9

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.

Performance

Twig compiles templates into optimized native PHP code, offering faster execution times than Smarty in most scenarios.

Security

Twig’s design encourages a stricter separation of logic and presentation (MVC), reducing the risk of PHP code injection.

Standardization

Since the Back Office uses Symfony, using Twig (Symfony’s default engine) unifies the development experience.

Syntax Showdown: 12 Practical Examples

1. Displaying a Variable (Output)

Most fundamental operation. Twig uses {{ }} exclusively for printing output.

Smarty <h1 class="text-3xl font-bold"> {$product.name} </h1>
Twig (Modern) <h1 class="text-3xl font-bold"> {{ product.name }} </h1>

2. Default Values (Null Coalescing)

Twig treats modifiers as functions with parentheses () .

Smarty <p> {$desc|default:'No description.'} </p>
Twig (Modern) <p> {{ desc|default('No description.') }} </p>

3. Assigning Variables

Twig uses {% set %} which is much cleaner than Smarty's assign tag.

Smarty {assign var='color' value='bg-red-500'} <span class="{$color}">Sale</span>
Twig (Modern) {% set color = 'bg-red-500' %} <span class="{{ color }}">Sale</span>

4. Conditional Logic (If/Else)

Note the lack of $ prefix for variables inside Twig's logic tags.

Smarty {if $qty > 0} <span>In Stock</span> {else} <span>Out of Stock</span> {/if}
Twig (Modern) {% if qty > 0 %} <span>In Stock</span> {% else %} <span>Out of Stock</span> {% endif %}

5. Loops (Foreach)

Twig uses Python-like for item in list syntax.

Smarty {foreach from=$products item=p} <div>{$p.name}</div> {/foreach}
Twig (Modern) {% for p in products %} <div>{{ p.name }}</div> {% endfor %}

6. Translations (i18n)

The {l} tag is replaced by the trans filter.

Smarty {l s='Add to cart' d='Shop.Theme.Actions'}
Twig (Modern) {{ 'Add to cart'|trans({}, 'Shop.Theme.Actions') }}

7. Inheritance

Extending base templates is syntactically clearer in Twig.

Smarty {extends file='page.tpl'} {block name='content'} <h1>Hi</h1> {/block}
Twig (Modern) {% extends 'page.html.twig' %} {% block content %} <h1>Hi</h1> {% endblock %}

Common Pitfalls & Challenges

Strict Variable Scoping

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.

No More {php} Tags

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.

Missing Modifiers

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.

Hook Interoperability

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.

Consequences for Module Developers

  • 1

    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).

  • 2

    Logic Migration: Smarty allowed "lazy" PHP logic in templates. Twig is restrictive. Logic must move to PHP classes/controllers.

  • 3

    Refactoring Costs: Agencies with libraries of custom modules will face a significant refactoring burden. The sooner this starts, the better.

Zdjęcie autora: Milosz Myszczuk

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!

Comments