Working 'Smarter' with Templates - Common Mistakes with Smarty
(Page 6 of 6 )
Doing comparisons in a loop (section)
It's best to do your comparisons in your php and pass the final recordset down to Smarty. This greatly improves performance. This really applies to anything you would do with smarty in a section loop. If possible, do your programming in your php and pass a ready-to-go recordset to Smarty.
Mixing “Some” HTML into your PHP code
It is almost unavoidable to put some HTML into your PHP code, but you must resist this at every opportunity. As more and more HTML begins to creep into your PHP you will find the benefits of templates diminishing.
Overuse of Smarty Functions
Many developers become so enamored with the convenience of the Smarty functions that they tend to overuse them in their templates. Too much of this behavior and you have the same problem that you had before templates only with a whole new subset language – not the ideal situation.
“Some” Templatizing
Using templates doesn't have to be an all-or-nothing proposition, but templates become more hassle than they are worth when used in some areas of the site but not in others. This practice leads to several versions of the same page lying around waiting to make your life miserable down the road.
Wrapping it Up
If you're looking to simplify/streamline your design and development process, templates are definitely one of the major components to reach that goal. Of the various templates out there, I chose Smarty. My suggestion to you would be to try a few of them on small projects and come to your own conclusions about which system might be right for you. If you decide to give Smarty a go and need a hand here and there, don't hesitate to give me a shout by clicking on the Discuss link for this article and I'll help where I can. Also, if interested, I can provide many real-world examples of more advanced uses of Smarty.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |