Smarty

" A PHP Template Engine. "

Smarty is known as a "Template Engine", as well as a "Template/Presentation Framework." It provides the programmer and template designer with a wealth of tools to automate tasks commonly dealt with at the presentation layer of an application.

Smarty templates get compiled to PHP files internally (once), eliminating costly template file scans and leveraging the speed of PHP op-code accelerators.

To facilitate the separation of application code from presentation. Typically, the application code contains the business logic of your application, written and maintained in PHP code. This code is maintained by programmers. The presentation is the way your content is presented to the end user, which is written and maintained in template files. The templates are maintained by template designers.

Features of Smarty:
  • Caching: Smarty provides fine-grained caching features for caching all or parts of a rendered web page, or leaving parts uncached. Programmers can register template functions as cacheable or non-cachable, group cached pages into logical units for easier management, etc.
  • Configuration Files: Smarty can assign variables pulled from configuration files. Template designers can maintain values common to several templates in one location without intervention from the programmer, and config variables can easily be shared between the programming and presentation portions of the application.
  • Security: Templates do not contain PHP code. Therefore, a template designer is not unleashed with the full power of PHP, but only the subset of functionality made available to them from the programmer (application code.)
  • Easy to Use and Maintain: Web page designers are not dealing with PHP code syntax, but instead an easy-to-use templating syntax not much different than plain HTML. The templates are a very close representation of the final output, dramatically shortening the design cycle.
  • Variable Modifiers: The content of assigned variables can easily be adjusted at display-time with modifiers, such as displaying in all upper-case, html-escaped, formatting dates, truncating text blocks, adding spaces between characters, etc. Again, this is accomplished with no intervention from the programmer.
  • Template Functions: Many functions are available to the template designer to handle tasks such as generating HTML code segments (dropdowns, tables, pop-ups, etc.), displaying content from other templates in-line, looping over arrays of content, formatting text for e-mail output, cycling though colors, etc.
  • Resources: Templates can be pulled from any number of sources by creating new resource handlers, then using them in the templates.
  • Plugins: Almost every aspect of Smarty is controlled through the use of plugins. They are generally as easy as dropping them into the plugin directory and then mentioning them in the template or using them in the application code.
  • Add-ons: Many user-community contributed Add-ons are available such as Pagination, Form Validation, Drop Down Menus, Calander Date Pickers, etc. These tools help speed up the development cycle.
  • Debugging: Smarty comes with a built-in debugging console so the template designer can see all of the assigned variables and the programmer can investigate template rendering speeds
  • Compiling: Smarty compiles templates into PHP code behind the scenes, eliminating run-time parsing of templates.
Reasons for using Smarty
  • It is free and open source and build in php and mysql.
  • Designers can't break application code. They can mess with the templates all they want, but the code stays intact.
  • Errors in the templates are confined to the Smartys error handling routines.
  • With presentation on its own layer, designers can modify or completely redesign it from scratch, all without intervention from the programmer.
  • Programmers aren't messing with templates. They can go about maintaining the application code, changing the way content is acquired, making new business rules, etc. without disturbing the presentation layer.