Smarty
A PHP template engine that compiles templates into native PHP, cleanly separating presentation from application logic.
Created by Monte Ohrt and Andrei Zmievski (Smarty 1–2); later Monte Ohrt and Uwe Tews (Smarty 3), with the wider Smarty community and New Digital Group, Inc.
Smarty is a template engine for PHP that compiles templates into plain PHP scripts, allowing web designers and application developers to work independently by keeping presentation (HTML/CSS) separate from business logic. Rather than embedding raw PHP throughout markup, developers write Smarty templates — files (conventionally with a .tpl extension) that use a compact, curly-brace syntax such as {$variable}, {if}, and {foreach}. Smarty parses and compiles each template once into an equivalent PHP file, then reuses that compiled output on subsequent requests, so the runtime cost of the abstraction is small.
For roughly two decades Smarty has been one of the most widely deployed template engines in the PHP ecosystem, powering content-management systems, e-commerce platforms, and countless bespoke applications.
History & Origins
Smarty was created by Monte Ohrt and Andrei Zmievski at the very start of the 2000s as an open-source PHP template engine. Its exact debut year is contested: Wikidata cites an archived reference from January 2001, some sources give 2000, and the official project copyright (held by New Digital Group, Inc.) dates to 2002 — the last of these being a copyright-registration year rather than a first-release date. Smarty is therefore best described as first appearing around 2000–2001. It saw rapid early adoption — the XOOPS CMS, for example, adopted it as its default templating engine by 2002.
Smarty emerged during a period when PHP web applications commonly mixed HTML and PHP logic directly in the same files. This produced pages that were difficult for designers and developers to maintain jointly. Smarty offered a disciplined alternative: a dedicated presentation language whose templates could be edited by designers who did not need to know PHP, backed by an engine that a PHP application populated with data.
The project has passed through several major generations:
- Smarty 1 and 2 — the original engine and its long-lived, widely adopted successor, authored by Monte Ohrt and Andrei Zmievski (with contributions from Messju Mohr and others). The Smarty 2.x series ran on PHP 4 and PHP 5 and became a de facto standard for PHP templating.
- Smarty 3 — a complete rewrite led by Monte Ohrt and Uwe Tews (with Messju Mohr among earlier contributors), with Smarty 3.0.0 released in November 2010. It introduced an object-oriented internal architecture, a new parser, and template inheritance, and required PHP 5.
- Smarty 4 (2021) and Smarty 5 (2024) — modernized releases that track contemporary PHP versions.
Design Philosophy
Smarty’s design centers on a few consistent ideas:
- Separation of concerns — Templates describe presentation; application code prepares data. This lets designers and programmers collaborate without stepping on each other’s work.
- Compilation, not interpretation — Smarty translates each template into a native PHP script the first time it is used, then serves the compiled version thereafter. Because the compiled artifact is ordinary PHP, execution stays fast; the engine only recompiles when a template changes.
- A constrained presentation language — Smarty deliberately offers a simpler vocabulary than full PHP. This encourages keeping heavy logic out of templates, though Smarty is flexible enough to allow more when needed.
- Extensibility through plugins — Modifiers, functions, blocks, and filters can be registered to extend the template language for a given project.
Smarty also sits at the heart of a long-running community debate — often summarized as “PHP is already a template engine” — over whether a separate template language is worth the overhead. Smarty’s answer has been that a purpose-built, restricted syntax plus features like caching and template inheritance provide real value for teams that want a clean separation between design and code.
Key Features
Template Syntax
Smarty templates use curly-brace delimiters. Variables are output with {$name}, and control structures mirror familiar programming constructs:
| |
Modifiers
Modifiers transform a value at the point of output using the pipe (|) operator — for example {$name|escape} for HTML-escaping, {$text|truncate:100}, or {$date|date_format:"%Y-%m-%d"}. Modifiers can be chained and are a primary mechanism for formatting in templates.
Functions, Blocks, and Plugins
Smarty ships with built-in functions (such as {include}, {assign}, and {capture}) and supports custom plugins. Developers can register their own modifiers, template functions, block functions, and filters, extending the template language to fit a project’s needs.
Template Inheritance
Introduced in Smarty 3, template inheritance resembles object-oriented class extension. A child template can {extends} a parent and override named {block} regions, much like overriding methods on a subclass:
| |
| |
Caching
Beyond compilation, Smarty provides an optional output caching layer that can store the rendered result of templates (in whole or in part) to avoid regenerating pages on every request — useful for content that changes infrequently.
Escaping and Security
Smarty supports auto-escaping and provides the escape modifier for guarding against cross-site scripting when rendering user-supplied data into HTML. It also includes a security policy mechanism for constraining what templates are permitted to do, which is valuable when templates may come from less-trusted sources.
A Small Example
Populating a template from PHP looks approximately like this:
| |
The engine compiles page.tpl to a PHP file on first use, then renders it against the assigned data — producing HTML while keeping the PHP code free of markup.
Evolution
Smarty’s lineage has emphasized stability punctuated by occasional deep rewrites:
- Smarty 2.x — The mature, extremely widely used series that ran on PHP 4 and 5 and cemented Smarty’s popularity across CMS and e-commerce projects.
- Smarty 3.x (November 2010 onward) — A ground-up, object-oriented rewrite that added template inheritance and a new parser while targeting PHP 5. The 3.1.x line proved remarkably long-lived, continuing through releases such as 3.1.40 in 2021.
- Smarty 4.0.0 (November 25, 2021) — Largely compatible with Smarty 3, this release added full PHP 8 support and dropped older PHP versions (requiring PHP 7.1+).
- Smarty 5.0.0 (March 25, 2024) — A modernization that adopted PHP namespaces and aligned the engine with current PHP runtimes (roughly PHP 7.2 through PHP 8.x).
- Smarty 5.8.x (2026) — Ongoing maintenance of the 5.x series, with release 5.8.4 published in June 2026.
Development is hosted on GitHub under the smarty-php/smarty repository, and the library is distributed via Composer/Packagist. Smarty is released under the GNU Lesser General Public License (LGPL).
Current Relevance
Newer PHP template engines — most prominently Twig (used by Symfony and, by default, modern Drupal) and Laravel’s Blade — have captured much of the mindshare for greenfield PHP projects. Even so, Smarty remains actively maintained and broadly deployed:
- Large installed base — Major platforms such as PrestaShop, along with systems like XOOPS, CMS Made Simple, Tiki Wiki CMS Groupware, and Piwigo, ship or historically shipped with Smarty, giving it an enormous footprint of existing themes and templates. (PrestaShop began migrating toward Twig in version 1.7, though Smarty remains in use for its theme templates.)
- Continued releases — With Smarty 5 modernizing the codebase and regular maintenance releases into 2026, the project keeps pace with current PHP versions.
- Familiarity and stability — For long-lived applications, Smarty’s mature, well-documented syntax and its strong backward-compatibility record make it a dependable choice.
Why Smarty Matters
Smarty was among the most influential early answers to a foundational question in PHP web development: how to keep design and logic apart in a language that, by default, freely intermingled them. Its compile-to-PHP model demonstrated that a dedicated template language could deliver clean separation of concerns without a heavy runtime penalty, and features it popularized — modifiers, plugins, output caching, and template inheritance — became common expectations for PHP template engines that followed.
Two decades on, Smarty endures both as living software and as a piece of PHP history: a pragmatic, widely adopted tool that helped shape how a generation of PHP applications organized their presentation layers.
Timeline
Notable Uses & Legacy
PrestaShop
The open-source PrestaShop e-commerce platform uses Smarty as its default theme template engine, rendering storefronts from .tpl files that separate HTML/CSS presentation from shop logic.
XOOPS
The XOOPS content-management system has used Smarty as its default view-templating engine since 2002, letting theme authors design layouts independently of module code.
Piwigo
The open-source Piwigo photo-gallery application uses Smarty to render its themes, letting users customize gallery presentation independently of the underlying PHP code.
CMS Made Simple
CMS Made Simple uses Smarty as its templating layer, exposing Smarty tags and template inheritance to designers through its design and template management tools.
Tiki Wiki CMS Groupware
The Tiki Wiki CMS Groupware project uses Smarty templates to render its extensive set of wiki, CMS, and groupware features.
TestLink
TestLink, a widely used open-source test-management application, relies on Smarty to render its web interface, separating page markup from PHP application logic.