Is Smarty really obsolete?

Tags:

There was a short discussion on Zend Framework general mailing list about Smarty being obsolete. I decided to take my opinion here, since the discussion was getting quite off-topic…

Arguments against Smarty presented were mainly the facts that it is PHP4 and its no longer necessary in “modern” web development.

Note: This post was written in 2008.. Although the points are still valid, I would recommend a more modern alternative, such as Dwoo or Twig, instead of Smarty now.

The arguments

Saying Smarty is PHP4 is correct. It may even affect people’s tendency to use it in PHP5 projects, but let’s imagine for a moment that Smarty was actually built for PHP5. We could even take some other template engine, instead of Smarty, that’s built for PHP5. Are those obsolete as well?

Another thing was that CSS somehow makes Smarty unnecessary. Because nowadays CSS is widely used, you can simply create a neat HTML markup and let your designers alter your CSS… Which works OK for small modifications, but more often than not, big modifications require changes in the HTML as well.

It (Smarty) creates extra presentation layer so designers don’t
have to deal with files containing PHP code. But this is exactly what CSS is
for, designers can use external stylesheets to completely change look and
layout of a page. As a developer all you need is serve content with simple
markup and you don’t need a template engine to achieve that

This is a direct quote from the mailing list. To claim you can achieve that with CSS is dubious – You would need to serve XML and let the designers work with XSLT if you wanted something like that…

The opinions also included that MVC frameworks played a part in obsoleting Smarty. I think we can safely say that it’s not true, since Smarty could be perfectly well used for the V-part of MVC. In fact, it has an advantage there: You can enforce what can go in the views, instead of just being able to do anything. No non-view related logic in views may require some discipline from developers and I think a template engine could be used to help with that.

Smarty has its issues too

Don’t get me wrong: Smarty does have problems. PHP4, speed, the code may be a bit of a mess… but it was always like that. WordPress can be slow and its code isn’t very great either, but the thing is that it works and does the job it’s supposed to do – just like Smarty does.

There may be alternatives that suit your needs better, but if you need a feature-rich template engine and don’t mind the aging, Smarty is still a good choice. For example, if you let your site users customize their personal page’s layout, a template engine would fit the task much better than giving them freedom to use PHP.

You may not need a template engine, you probably never did (it was always possible to just echo stuff), but I think template engines have few uses left. It should probably be mentioned that you can’t embed languages like Python to HTML, so things like Django require the use of a template engine!

If you don’t like Smarty, fine. Just don’t hide behind dubious reasons that you can’t explain properly ;)