After this ONLamp article, I decided to take a look at PEAR:: DB and Smarty. I passed on PEAR:: DB for now because the class I use for database access works pretty well for now, but I liked what Smarty claimed to be so I downloaded it and got to work.
All I can say is Wow. I re-wrote a couple pages from Dawg Tag and everything flowed so much better.
Using only PHP, writing only application code invariably involves thinking about the design of the resulting page. Scripts are full of html code, and changing the appearance of a page means editing script files, being careful not to break them.
Smarty made all of that better. Now, my script files have no html code. All application code goes in the regular php file so you can just build arrays, fill variables, manipulate data without worrying about what it will look like. Then, any variables or arrays that need to be in the output are just assigned to Smarty, where you lay them out in a seperate template file.
The templates are ridiculously easy to work with. Basically, they are plain html files with some variables pulled in from the application, beautiful.
I will be using this for any project I work on from now on. The documentation is good, the syntax is easy, and the result is cleaner code with less headaches.
Highly recommended!
12/11/04: PHP Templates With Smarty - Recommended
After this ONLamp article, I decided to take a look at PEAR:: DB and Smarty. I passed on PEAR:: DB for now because the class I use for database access works pretty well for now, but I liked what Smarty claimed to be so I downloaded it and got to work. All I can say is Wow. I re-wrote a couple pages from Dawg Tag and everything flowed so much better. Using only PHP, writing only application code invariably involves thinking about the design of the resulting page. Scripts are full of html code, and changing the appearance of a page means editing script files, being careful not to break them. Smarty made all of that better. Now, my script files have no html code. All application code goes in the regular php file so you can just build arrays, fill variables, manipulate data without worrying about what it will look like. Then, any variables or arrays that need to be in the output are just assigned to Smarty, where you lay them out in a seperate template file. The templates are ridiculously easy to work with. Basically, they are plain html files with some variables pulled in from the application, beautiful.
I will be using this for any project I work on from now on. The documentation is good, the syntax is easy, and the result is cleaner code with less headaches. Highly recommended!