Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Your Ad Here

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.

Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Your Ad Here
Wallpaper 312
Statistic


Last Post

 
Top! Top!