Smarty allows you to specify (‘register’ or ‘load’ actually) filters through which you can run your templates before or after they are compiled. Prefilters are functions that your templates are run through before they’re compiled; postfilters after; and output filters, upon the template output as it is requested.
‘Why filters?’ you say. Prefilters allow you to do things like removing unwanted comments (such as those created by Dreamweaver) and ensuring content in the templates you don’t want does not go through to the compiler. Postfilters let you add additional information to your templates, such as the template creation date (as a comment) after they’re compiled. Output filters give you the ability to modify your template output, allowing you to do things like obfuscating email addresses on your Web page to protect against spambots (using a preg_replace()).
Config files are configuration files where you can store global template variables. This allows you to store variables that should affect every template (i.e. global variables) in a central location. A good example of such a variable would be the color scheme for your templates. Your template designers only have to change the values in the config file should a color scheme revamp be required. This saves them suffering through the painful alternative of going through every individual template to change the colors.
Config files also allow for sections, which are not unlike those in .ini files. The section names are enclosed in brackets (e.g. [welcome_page]) and are only loaded upon request. Anything that’s not in a section is globally available (upon a call to the config_load function).
The Smarty plug-in architecture was introduced in version 2.0 and allows you to customize Smarty to suit your purposes (however grand or nefarious). The prefilters, postfilters and output filters I discussed earlier are just some of the plug-in types available to the customizer. Other plug-in types are the modifier, block, compiler, resource and insert types.
With plug-ins, you can create your own template functions, variable modifiers and filters. You can even change the data source you want Smarty to read from (the default is from flat files), using a resource plug-in. With a resource plug-in, you can save your templates in a database, and retrieve them using sockets (or any other method you use to access templates with PHP. This means you can access just about any source).
Smarty is a quality template engine and one you should definitely consider, should you be on the lookout for a PHP version.
Combine Smarty’s template compilation and PHP’s inherent efficiency in generating Web pages, and you’ve got yourself a winner in the speed race. Smarty also offers extensive functionality, including template functions and variable modifiers, which can be extended using a well-designed plug-in architecture.
All that speed and functionality doesn’t come at the price of usability: the learning curve is no steeper than that of other template engines. Smarty is also supplemented with excellent documentation that’s available online and for download at the Smarty Website.
Andrei Zmievski, one of the authors, works on the PHP development team too, and he keeps Smarty’s development closely tied to that of PHP. So you can be confident that the latest changes to PHP (like the recent register_globals issue in PHP 4.2.0) will be supported by Smarty.