Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

View the Project on GitHub smarty-php/smarty

Basic Syntax

A simple Smarty template could look like this:

    {foreach $cities as $city}
        <li>{$|escape} ({$city.population})</li>
        <li>no cities found</li>        

All Smarty template tags are enclosed within delimiters. By default these are { and }, but they can be changed.

For the examples in this manual, we will assume that you are using the default delimiters. In Smarty, all content outside of delimiters is displayed as static content, or unchanged. When Smarty encounters template tags, it attempts to interpret them, and displays the appropriate output in their place.

The basis components of the Smarty syntax are: