| PHP The Smarty Template Engine |
Smarty is an incredibly powerful and complex templating system available for PHP developers. It is perhaps the best common-ground solution I've ever seen and balances the separation of presentation and application logic without sacrificing usability. Although it functions on an entire template-scripting language of its own, the use of this functionality is not a requirement.
When I was first introduced to the Smarty package, I was immediately turned off to it when I saw the first complex example. This template example was truly a program in its own right, complete with control structures, internal function calls, and more. My thoughts kept coming back to the reason for template engines in the first placeto free the Web designer from having to mess around with PHP code! It seemed to me that although Smarty may have separated PHP from HTML, the solution required Web designers to learn an entirely different Smarty "scripting" language. All in all, I was very disappointed and quickly removed Smarty from my system.
Sometime later I was doing research for a column I was in the process of writing about the separation of application and business logic, and I happened to run across Smarty again. For the sake of completeness, I decided to include a little about Smarty in my articlewhich, of course, forced me to learn a bit about using it. As I got the Smarty documentation out and began playing with it, I started changing my opinion of the scripting engine. Although it did have some very complex features for a template engine, it also supported the plain old variable substitutions that you were introduced to in my discussion of QuickTemplate. The engine also supported the bare set of control structures, such as conditional statements and loops, allowing for complete separation of presentation and application logic. With all this functionality, you would expect Smarty to be slow; however, perhaps the thing that blew me away the most was that it was fastfaster than any PHP template engine I had ever seen! I have since changed my opinion of the Smarty templating system and now consider myself a die-hard fan.
How does the Smarty template engine do it? Smarty works on what (to my knowledge at least) is a unique concept to any PHP templating systemit compiles the templates into native PHP code. Hence, the first time a template page is loaded, Smarty compiles it into a PHP script first, which is saved, and then executes the template code. This makes the template almost as fast as PHP itself and incredibly scalable. To top it off, the engine was designed in such a way that the control structures it provides were converted directly into PHP code, giving them all the flexibility and power of the actual PHP equivalents without the inherent complexity.
| Users' Comments (0) |
|
No comment posted








