Is Smarty really obsolete?

July 19, 2008 – 2:28 pm 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.

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 ;)

  1. 7 Responses to “Is Smarty really obsolete?”

  2. In the ideal world all design could be made through CSS - although the world is not ideal so in reality it doesn’t really work out that way as you say.

    I agree with you that template engines are good for 3:rd-party enhancements - but I think that in PHP they don’t belong in your own native code.

    PHP is a good enough template engine in itself and a separate template engine would only be needed if you would like to limit the powers of a template - which would be wise if that template is made by a 3:rd-party.

    By Pelle on Jul 19, 2008

  3. regardless of whether one considers php to be a good enough template engine or not (everything has been said imho…) -> check out http://dwoo.org/, a php5 template engine which is smarty compatible, and has some nice additional features over smarty.

    By keschte on Jul 19, 2008

  4. Thanks, keschte. I was going to mention dwoo as a more modern alternative in this post, but I had forgotten the name :)

    What comes to presentation with CSS, perhaps the situation will get better with HTML5 and CSS improvements. Who knows, perhaps one day…

    By Jani Hartikainen on Jul 19, 2008

  5. I have a love hate relationship with Smarty..

    I love some of the options it offers (first, last etc in loops for instance)
    But I really hate that you sometimes have to jump through complex hoops to get it to do something you would be able to do in PHP without touble, sure you have the {php} {/php} tags but that looks very ugly compared to direct php.

    By Harro on Jul 19, 2008

  6. I never heard of Dwoo before but I gave it a try… and I love it !

    It’s all the good stuff of smarty and (so far as I can tell) non of the bad stuff !

    Sure it needs some work, but I like the fact that it supports the basic stuff and let’s me add the rest myself :)

    By Harro on Jul 20, 2008

  7. You made you points clear, and in the end is a personal desition if you use it. Personally I dont like Smarty nor any other template engine. This is why:
    - In the MVC pattern: why to add another layer to the View? that means more processing, more memory, etc.
    - If view is just to print, then and echo is ok, even use the php way to do it . it’s the same principle that smarty. you would say for caching but thats a controller specific job so it would break MVC.
    - Designer are nod coders, but smarty is a code language with its own language, so why not use php. if they need loops thats programming so use php, or I dont hire you.

    Finally to conclude smarty is another way to write php code, that is useless. and I think if designers complain about this is because they are mediocre. Q: if a designer knows how to create a complex animation in flash why they would not do some simple job with php???

    By neonard0 on Jul 22, 2008

  8. I have never liked Smarty.

    Also, I don’t understand why it is not more common to use XSLT..

    It’s a standard, it’s flexible, allows an extra level abstraction using Two Step View [Fowler] and PHP’s support of it is great (wish it came standard though).

    By John Kleijn on Jul 30, 2008

Post a Comment