How To Use PrestaShop 1.7 Smarty Template In 2026

Jun 26, 2018 21758 Updated: July 8, 2026
How To Use PrestaShop 1.7 Smarty Template In 2026

Smarty is a PHP template handler. It provides one of the tools that allows you to divide the visual part from the server part of the site. This is very convenient when the programmer and the template designer are two different people.

Smarty features:

  • Fast.
  • Effective (the PHP handler does all the work).
  • Templates are compiled only once.
  • Templates with changes are transcoded.
  • You can easily create your own custom functions and variable modifiers, which makes the template language extremely extensible.
  • The {if} {elseif} {else} {/if} constructs are passed to the PHP handler, so the syntax of the {if …} expression can be as simple or as complex as you like.
  • Unlimited nesting of sections, conditions, and the like is permissible.
  • It is possible to include PHP code directly in your template, but this is usually unnecessary (and not recommended), since the engine is very flexible and extensible.
  • Built-in caching mechanism.

Let us create something in the index.php file:

To output our values in Smarty, we use the {tags} construction. The code and the name of the variables are written in curly brackets. The information is displayed dynamically.

Just like in PHP, variables start with the $ sign. Also, please note that the syntax {….} works only in files with the *.tpl extension.

The contents of the file with the *.tpl extension:

Output:

You probably noticed that Smarty is separated from HTML and PHP code. This was created in order not to mix things up. The design can be adjusted by a usual front-end developer, and the back-end can easily make its own edits. However, in Smarty, you can edit content views at once using modifiers.

Let’s change the text that we wrote earlier.

index.tpl file:

What did we do?

First, we have every word of our name derived from a capital letter. Secondly, we made a special character just a markup of the mnemonics. Thirdly, we displayed the date.

The result:

In Smarty, you can make your own modifier with its easy-to-use architecture. To do this, add a new modifier to the plugin’s directory, and then specify it in the template.

You can also control the output of information in a template, or rather, break it into pieces. The {include} function will help us put everything together. Let’s break our example into templates, or rather, our HTML code. Create a header.tpl file and put the top of the template there, and the bottom part in the footer.tpl file.

Header.tpl

Footer.tpl

Now we include everything in the index.tpl file.

{include file=”header.tpl” title=”Info”}

User Information:<p>

Name: {$name|capitalize}<br>
Phone: {$phone|escape}<br>

{include file=”footer.tpl”}

You might have noticed that we can now control the code that used to repeat across several pages. Now, to make changes, we only have to edit 1 file.

Smarty also has built-in caching capabilities to speed up page rendering. A copy of the template output file is saved to a text file and then displayed on subsequent query calls instead of dynamically rendering the page each time. This can significantly speed up page rendering, especially if you need a lot of processing to create the page, such as database calls and variable assignments. You can also leave the parts of the page dynamic simply by marking them as nocache.

You can also have multiple cached versions of the same page, passing a unique cache identifier to the display() function. See the documentation for details.

Correct names

The plugin files should be named as follows:

Type.name.php, where type can be:

  • function
  • modifier
  • block
  • compiler
  • prefilter
  • postfilter
  • outputfilter
  • resource
  • Insert

Name can contain numbers, letters, and underscores.

Examples: resource.db.php, modifier.spacify.php.

Plugins and their work

In Version 2.0, the plugin architecture was introduced, which is used for almost all configurable Smarty functions.

  • functions
  • modifiers
  • block functions
  • compiler functions
  • prefilters
  • postfilters
  • outputfilters
  • resources
  • Inserts

Everything except RESOURCES is compatible with the old methods of processor functions registration using register_ * API. If you did not use the API, but used the variables $custom_funcs, $custom_mods, etc, then you’ll need to configure your scripts or still use the API. There is also an option to convert custom functions into a plugin.

How plugins work

Plugins can either be downloaded automatically by Smarty from the file system or registered while running via one of the register_* API functions. They can also be registered using the unregister_ * API functions. Only certain modifiers, functions, resources, etc., which are called in template scripts, will be loaded with plugins. Each plug-in is downloaded only once, even if you have multiple instances of Smarty running in a single query.

Pre-filters / post-filters and output filters are a special case. Since they are not mentioned in the templates, they must be explicitly registered or loaded via API functions before the templates are processed. The execution order of several filters of the same type depends on their registration or upload order.

Template functions

Here is the structure:

void smarty_function_name($params,$template);

where $params is an array, and $template is an object. The attributes we pass to the template function are stored in the associative $params array. The result will be replaced by the function tag in the template. If the function needs variables in the template or other Smarty functionality, you can use the $template object. For example, $template -> foo().

Applying this example:

Question: How often do you break the traffic rules?
Answer: {testings}.

That’s it on the Smarty template engine. Hope it was useful and clear, and you will use this information to improve your webstore. Find more helpful PrestaShop modules at the PrestaShop module store by BelVG. If you still have some questions, please leave them in the comment section below.

prestashop 1-7 compatible Modules

Prestashop Extensions

Take your online store to the next level with new features

Visit the store

FAQs for PrestaShop 1.7 Smarty Template

What is Smarty in PrestaShop?

Smarty is the template engine PrestaShop uses to display content on your store. It separates HTML and PHP, allowing developers to create themes more easily by working with files of Smarty .tpl in PrestaShop. Smarty handles dynamic content and ensures better organization and performance, making it a key part of PrestaShop 1.7's templating system.

How does Smarty work in PrestaShop 1.7?

PrestaShop Smarty takes template files (.tpl) and fills them with data from your store to create the final HTML pages. It uses tags like {$product.name} to show dynamic content and supports features, such as conditions, loops, caching, and template inheritance to control how pages are displayed.

Is Smarty still used in PrestaShop?

Smarty is still used in PrestaShop, including version 1.7 and beyond. It remains the default template engine, allowing developers to separate logic from design using .tpl files. Smarty functions in PrestaShop help manage dynamic content, template inheritance, and custom variables, making it a key part of theme customization.

Post a new comment