Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic. This implies that PHP code is application logic and is separated from the presentation.
When it comes to templating in PHP, there are basically two camps of thought. The first camp exclaims that "PHP is a template engine". This approach simply mixes PHP code with HTML. Although this approach is fast from a pure script-execution point-of-view, many would argue that the PHP syntax is messy and difficult to maintain when mixed with presentation. PHP works well for programming, but not so well for templating.
The second camp exclaims that presentation should be void of all programming code, and instead use simple tags to indicate where application content is revealed. This approach is common with other template engines (and other programming languages), and is the approach that Smarty takes. The idea is to keep the templates focused squarely on presentation, void of application code, and with as little overhead as possible.
Smarty is a template engine, and works as the (V)iew component of your application. Smarty can easily be coupled to any of the engines listed above as the view component. No different than any other software, Smarty has a learning curve. Smarty does not guarantee good application design or proper separation of presentation, this still needs to be addressed by a competent developer and web designer.
The Goals of smarty
- Clean separation of presentation from application code
- PHP backend, Smarty template frontend
- compliment PHP, not replace it
- fast development/deployment for programmers and designers
- quick and easy to maintain
- syntax easy to understand, no PHP knowledge required
- flexibility for custom development
- security: insulation from PHP
- free, open source
How does it work?
Under the hood, Smarty compiles copies of the templates as PHP scripts. This way you get the benefits of both template tag syntax and the speed of PHP. Compilation happens once when each template is first invoked, and then the compiled versions are used from that point forward. Smarty takes care of this for you, so the template designer just edits the Smarty templates and never has to manage the compiled versions. This approach keeps the templates easy to maintain, and yet keeps execution times extremely fast. Since the compiled versions are PHP, op-code accelerators such as APC or ZendCache continue to work on the compiled scripts.
Red Symbol Technologies - a professional web development company - offers exceptional solutions by providing dedicated Smarty developer services. Our skilled programmers ensure the best results utilising all the features and functions of this template engine. contributing to the overall success of your business.