Although I’ve always agreed on the MVC pattern, specially the separation between the business and the presentation logics, I have to confess that throughout the years, my opinion about using template engines has changed a few times.
Back in 2003, I converted some of the IMP pages to templates and contributed some code to the Horde Templates engine. Back then, I presented some arguments in favor of template engines and one of the main reasons was the ability to send the templates to designers and have them doing what they want with them.
My experience quickly proved that I was wrong. Besides the fact that I added a bunch of lines to the code to define the template variables, the designers still needed a lot of help to customize the templates. Also, the code was slower until a template compiler was developed. Overall, the benefit from all that was null.
Since then, I think template engines are useless for most of the cases. I still agree you should separate business and presentation logics, but you can do it with PHP, you don’t need a different language for that.
Hasin Hayder, the author of a Smarty book, has an interesting post from earlier this year where he says that there’s no need of Smarty anymore:
I just dont need a wrapper over my PHP code which parse regular variable and echo them. Smarty just made itself extremely complex and useless too over the day, seriously.
I seriously don’t think there is need of Smarty anymore. Its dead!
There’s also a lot of buzz around the subject. You can also check the posts from Paul M Jones, and Michael Kimsal.
I have to say I agree, template engines are only useful when they keep the template language really simple (ie, way simpler than the language used for business logic).
The only template language I’ve enjoyed working with so far was django‘s.
I use Smarty a lot. It helps me keep the code organized and well structured. However it is true that new PHP frameworks offer a lot of features (helpers, cache, etc) that make Smarty useless.
Adding Smarty to an MVC framwork is like adding sugar to a hot chocolate. There’s already too much of it there.
So either I use Smarty in smaller projects or frameworks for bigger things.
I’m not against template engines because the new PHP frameworks offer a lot more features.
I’m against template engines because I think they are useless. I can do the same stuff directly in PHP and with my past experience I don’t buy the reasons people say in favor of template engines.
I agreed with the template engines way 4 years ago. What changed my mind was my experience, that’s it.
Couldn’t agree more.
“separation between the business and the presentation logics” doesn’t have nothing to do with using template systems.