Say "No" To Smarty!

By | February 4, 2009

I just discovered nosmarty.net in my Solar referrer logs. I have little love for Smarty, so it’s nice to see this:

First released in January 2001, Smarty has become a stagnant, bug-ridden mess—and also the most popular PHP templating engine in use today. But it shouldn’t be. No Smarty was created to warn developers about its use and encourage the use of superior alternatives.

Hey guys, you might want to add Savant to your list of PHP5 alternatives. Aside from that, great site!

UPDATE: To those who think my tone is inappropriate — “I’m not disrespectful, I’m just ahead of the curve.” </joker> ;-)

UPDATE (Thu 05 Jan): Please note that I am not affiliated with nosmarty.net in any way. I just saw it in my referrer logs and linked to it in this post. Thank, Ivo Jansch, for pointing out the need for clarity here.

UPDATE (Thu 05 Jan 10:56): A commenter below opines “If Smarty is used in the right manner, I don’t see why it can’t have it’s place within the arsenal of tools for developers to use.” I respond that there *is* no right manner in which to use Smarty; it’s solving the wrong problem. I expound on that here:

You may have heard that you need to keep your PHP and HTML separated, but that’s not quite the case. Instead, what you need is to keep your “business logic” separate from your “presentation logic”, and that’s a different thing entirely.

Thus, all that’s required is a way to keep your views and controllers separated, and perhaps provide helpers for common view tasks. Then you can use plain PHP in your view scripts (templates), without needing a whole new language.

52 thoughts on “Say "No" To Smarty!

  1. Lukas

    Way to encourage respect for other peoples work. Do not get me wrong, I also do not think that from todays perspective Smarty is a good idea, but finding pleasure in someone else “ripping it a new one” is kind off lame .. even pathetic when used as a plug for your own stuff.

    Try to learn how to disagree respectfully.

    Reply
  2. pmjones Post author

    I don’t think anyone’s “ripping it a new one” (as you put it), and I don’t think it’s “disrespectful” to agree with others who think Smarty’s time has passed.

    Reply
  3. till

    I gotta agree with Lukas. You have to admit that Smarty had its time and even though most people moved on, it’s still one of the most comprehensive templating engines today. I never regret using Smarty, it helped me lots and served me well.

    And point taken, if you use one of the MVC frameworks Smarty might be not necessary because they bundle what Smarty ships, but there are also a lot use cases which Smarty caters.

    All in all, of course there are lots of things which Smarty could use, but so do a lot of open source projects. Feature request never come short, while participation is an exception.

    And before people make up claims they should check out the website — e.g. release in December 2008 and also a note that there is an alpha of Smarty3.

    Reply
  4. till

    It’s also hilarious that the smart people from nosmarty.net (hoho) didn’t even have the skills to create their own design. Instead they ripped off Smarty’s and even put Google Ads on it.

    And thanks to sites like archive.org, the Internet will document all the stupidity until it’s all over. ;-)

    Reply
  5. pmjones Post author

    I reserve the right to offend, especially on my own blog. Frankly, I think my words are pretty tame; if you think (incorrectly) that my tone is disrespectful, well, you have a the right to say so.

    My opinion about Smarty is long-held and well-established. I’m just glad to see someone else who agrees with me in general about the need to move away from Smarty, and who is willing to put up a site to popularize that opinion.

    Reply
  6. pmjones Post author

    Of course they satirized the Smarty site — it’s part of the point. Hell, when I build Savant so long ago, I called it “Dummy” at first, and used a broken light bulb as the logo. Maybe not imaginative, but it gets the point across.

    Reply
  7. nate

    Lukas: Um, pot, kettle? I wasn’t aware of any social convention that defines pointing out deficiencies in software and offering alternative solutions as a form of disrespect. Passive-aggressive sarcasm, on the other hand — that’s more like what I’d call disrespectful.

    And another thing: yes, Paul wrote Savant… so what? Savant is a solid templating engine that’s stood the test of time and received high praise from many in the PHP community. The fact that Paul wrote it doesn’t invalidate his opinion on the subject. This issue has long been a serious deficiency of character in many members of the PHP community: assuming biases in others as an excuse to act like an ass.

    Reply
  8. Kaloyan K. Tsvetkov

    I wonder did this Kenneth Chau chap from NoSmarty.net ever really used Smarty or at least has he even read the crash-course ;) Some of the statements in NoSmarty.net are just ridiculous.

    Reply
  9. pmjones Post author

    Kaloyan — good catch. They should change the site to note that (and any other inaccuracies readers might find). Using incorrect information only undermines their laudable goal: i.e., to reduce the use of Smarty.

    Reply
  10. Leandro

    If your project goes well, you can always introduce Smarty – as a kind of challenge – to complicate the things and get absolutely nothing =P

    Reply
  11. Les

    Smarty was believe it or not, f*cked up when it was first released all those years ago and well… It’s still f*cked up to this day but like flies around sh*t we are stuck with it.

    No amount of warnings about the failings of Smarty are going to stop some people from using it, as that is how things are in this world but hey… Smarty isn’t alone you know, as we also have WordPress, another PHP application that has been f*cked up since it’s birth…

    So, what is it with PHP and these f*cked up applications?

    How come we get stuck with them huh?! I blame it all on those people out there who think they can be a web developer but without the background knowledge, ie the stupid ones.

    If you want to kill off Smarty, et al (and who doesn’t?) then we got to kill off those stupid individuals who go around thinking they’re a “software developer” when they are nothing like us real software developers who have the ability, the skill, the knowledge and experience to know better.

    Reply
  12. Bertrand

    PHP is still the most popular template engine for building websites…

    Reply
  13. Bertrand

    By the way, I once used Smarty as a template engine long time ago. It was a dreadful experience having to deal with cache files, precompiled templates, etc. The name Smarty sounds like a joke to me. It is one of the worst template engine I have met (eZPublish’s being another one). Smarty just adds a useless layer on top of native PHP features.

    On the other hand, I have used both Savant 2 and 3 and I still use them in all my large and small PHP projects. It’s clever. Not clever in the way it is implemented, I think the thing could handle plugins in a smarter way for example, it is just the idea that is clever.

    But it is not a template engine for PHP newbies because it can be dangerous if you don’t understand what MVC is.

    Paul M. Jones is doing you a favor in reminding you about his template engine. If you can’t understand that, I guess you are a PHP developer in the strict sense of the word.

    And Lukas, you sound completely out of scope. As if I was telling you “instead of whining on other’s blogs, you’d rather take care of PHP 5.3 release (for what I care about this version…)”.

    Reply
  14. TC

    They didn’t manage to copy the smarty design, they managed to break it in safari.
    Great advert for their skill and judgement.

    But I guess you’ll tell me next that I’m wrong for using a Mac or Safari.

    I think right about now might be time to unsubscribe from this blog, I think I’ll live without all the solar beta updates.

    Reply
  15. Andrei

    Seriously, it is not hard to bash something that has been around since 2001 and has accumulated some undesirable stuff. Interesting that he has enough time to create a site and proselytize, but not to contribute to fixing some of the issues.

    Also, his conclusion is to use ZF? As Rasmus says, the reply to that is in the form of an image:

    http://talks.php.net/presentations/slides/intro/zf.png

    Reply
  16. Radoslav Stankov

    Hm, I really like smarty, it have many features that make my code clear, I have really speed up my development type. PHP is template language indeed but the think that smarty do is to compile the templates into php code. Because, I don’t know for you, but using bare-naked php for output looks to ugly for me.

    Reply
  17. pmjones Post author

    Wim —

    OPT and Dwoo subscribe to the same honest-but-misguided basic principle as Smarty; that is, they invent a “template language” where none is needed. They’re not “alternatives to Smarty”, they’re “more of the same as Smarty”.

    Savant, Solar, Zend, Cake, Symfony, et. al. use plain PHP for the language, PHP functions/classes as helpers, and PHP object instances for view separation. These view systems are the superior alternatives to Smarty; there are also XML/XSLT systems, and (ugh) PHPLib type systems, which I wouldn’t wish on anyone these days.

    Reply
  18. David

    I used to use a templating language for my work (similar to smarty) but after swapping to good-old-PHP (made my own cut down version of Zend_View), my templates run faster, they’re easier to debug, and it’s even simplified other parts of my application code, where I was having to jump through hoops to get my my data into the template the way I wanted.

    So here’s my question. If you need to provide some form of templating for users (potentially public users, *NOT* developers), what templating language would you recommend?

    Reply
  19. David

    @Kaloyan
    He was probably looking for number_format, since that’s what it’s called in PHP. Sure string_format provides the same functionality via sprintf(), but it’s not readily apparent.

    Reply
  20. Kaloyan K. Tsvetkov

    @David: then he should bash the name convention, not something that’s apparently not missing ;)

    And Les:

    If you want to kill off Smarty, et al (and who doesn’t?) then we got to kill off those stupid individuals who go around thinking they’re a “software developer” when they are nothing like us real software developers who have the ability, the skill, the knowledge and experience to know better.

    …enough with the elitist crap ;)

    Reply
  21. pmjones Post author

    @Kaloyan: “…enough with the elitist crap ;)” Agreed. We’re trying to improve practices as a whole, not bash individual persons.

    Reply
  22. Ivo

    I had a response with something along the lines of a hammer and a screwdriver but I clicked the wrong button. It was an excellent metaphor though, and I’m sure you would’ve agreed with me. ;)

    Reply
  23. Evan

    I don’t understand how ZF or Symfony or any framework can be an “alternative” for Smarty. Smarty is not a framework — it is simply a templating engine. It should not be used as anything other than a component of the view layer of your MVC application. Just like any other software, it has a learning curve and a certain amount of quirks. Using Smarty does not guarantee good design — that still needs to be handled by programmers who have more experience than writing a “Hello, World!” program and reading a tutorial.

    I think the fact that it’s been around since 2001 and is still in use is a testament to it’s usefulness within the community. If Smarty is used in the right manner, I don’t see why it can’t have it’s place within the arsenal of tools for developers to use.

    Reply
  24. pmjones Post author

    @Evan —

    “If Smarty is used in the right manner, I don’t see why it can’t have it’s place within the arsenal of tools for developers to use.”

    In my opinion (note the small “o”) there *is* no right manner in which to use Smarty. It is the solution to a mis-stated problem. I suppose I shall have to expound on that at greater length in another blog post. Oh, I already have! http://paul-m-jones.com/?p=273

    Reply
  25. Pingback: Smarty, solving the wrong problem since 2001 « phpslacker

  26. kenrick

    I have never spent more time looking a documentation then the time I tried to use smarty on a project a few years ago. I applaud them for trying to solve a problem that really can just be fixed by only allowing people who know what they’re doing near your code.

    Really if you can’t trust your developers/designers/integration person to not put stupid crap in your templates for your project, you’ve hired the wrong person.

    Reply
  27. Pingback: dotEvan » Blog Archive » Why I use Smarty: PHP is an ugly templating language

  28. Kaloyan K. Tsvetkov

    Probably the correct way to put this is that there are certain areas that Smarty is less and less applicable to. However, there are still areas and situations, in which Smarty (or other similar template-engine solutions) will be irreplaceable. Like all the occasions that you have user-generated content: for example, imagine a service like Blogger/Blogspot, where you have the ability to customize the look and feel of your blog. You will never be allowed to use raw PHP syntax in there – never! And that’s probably why WordPress.com doesn’t have template editing for all the blogs hosted there: because WordPress themes & templates are pure PHP code.

    So if you want to built responsible services that allow your customers to edit their templates, say Yes to Smarty ;) And if you are building an application which will have just you and several other developers involved — use whatever makes your day ;)

    Reply
  29. pmjones Post author

    @Kaloyan — providing programming languages through web-based interfaces to untrusted customers is probably still not a good idea, and Smarty *is* a programming language. :-/ Simple replacement (block-and-loop) templates will do the trick there in almost all cases. Smarty is overkill for that purpose, but other low-powered template systems might be sufficient.

    Reply
  30. pmjones Post author

    @Kaloyan: if, then, else, for, foreach, print, variables, store value, modify value, functions, escaping, comments. Smarty might not be Turing-complete language, but those are all logical and programming constructs.

    Reply
  31. AppBeacon

    I love Smarty. I use it for my “real” job and my side project. I don’t like frameworks; so, I won’t use them.

    Smarty saves me from the heartache of seeing my HTML with all those damn php echo and escapes. When I am trying to change my HTML, I want to see HTML – not PHP. Smarty does this really well while making it easy to inject dynamic data.

    Every time I dig into some open source code to make changes to the output, I cringe. I love WordPress, but I can stand to see all that HTML mixed in with PHP. Echo this. Echo that. Escape in , escape out. Good grief.

    Go Smarty!

    Reply
  32. Guillermo

    Smarty it’s cool for letting non-techi users edit their own email templates and save them to a database for latter parsing..

    Using pure PHP in this case would be hard to archieve for 3 reasons:

    1. Any mistake could cause a fatal error.
    2. It may be complicated having to fetch php code from a database and executing it(besides it would be just too unsafe)
    3. It’s safe for the system that users edit Smarty code, without worring about security vulnerabilities.

    Reply
  33. Les

    Didn’t think I was being elitist?

    But was I? I only mentioned that because Smarty is bad (basically) we need to remove it from the PHP world and to do so we would also have to remove those who were responsible…

    Much like those who are also responsible for other badly developed, abeit popular applications, but yer… I can be a loose cannon sometimes ;)

    – Paul

    Excellent comments all round and hope you get your wish – a Smarty free world :)

    Reply
  34. Pingback: To Smarty or not to Smarty? | Mihai Brehar

  35. Bertrand Mansion

    If your templates have to be designed by non developers, use HTML_Template_Sigma, full stop. This will give you dumb templates that won’t contain any logic. This will grant you the MVC compliant badge.

    If you want to allow some programming in your templates and want to avoid security risks, use a sandboxed environment. Lua as a programming language is able to do just that. Watch for mod_lua in the next version of Apache (2.3) or investigate the PECL extension for Lua in PHP.

    Reply
  36. Tyrian Camilo

    Uh oh, this is in SO many ways wrong.

    Smarty makes development easier, it makes the HTML more readable, and it FORCES you to have certain standards of quality!

    If you don’t find Smarty easy to use, and forcing you to certain high quality of standard, you aren’t using it right.

    Smarty has one of the most simplest syntaxes, and helps you in so many ways to structure the template side of things, and it has totally neglible overhead.

    If you are sticking PHP in middle of smarty template, you are doing something terrible wrong. If you cannot use smarty without “cursing it’s buggy” you are doing something wrong.

    Smarty doesn’t bug, infact, in 7yrs of using it now, i’ve not encounted a single bug in my lifetime of using it.

    Oh, and for those VERY complex pieces, simply use an view helper, or custom function, but preferrably, just pass the data to smarty in a sane format.

    for example, BaseApp, someone’s “easy to install” base starting point for Zend Framework includes smarty, but the examples suck totally, they are so immensively stupidly templated that you got to wonder who can be such an idiot to put everywhere {assign} tags. and that integration totally sucks.

    Jani’s smarty integration (SmartyView & SmartyAdvanced) is good starting point but is bug riddled, need to fix the bugs in the integration, and then smarty is one pleasant templating to use.

    Case example:
    Search results, “legacy code”, no real MVC structure.
    In the end of code there’s an if ($_POST['rss'] == 1) $smarty->display(‘rss_results.tpl’) piece.
    Guess how fast it was to turn HTML to valid rss? ;)

    Reply
  37. Tyrian Camilo

    @kenrick

    I don’t understand what’s so hard about this:
    {$foo}
    {$foo|number_format}

    {section name=iloop loop=$foo}
    {$foo[iloop]}
    {/section}

    If you cannot master THAT, then you shouldn’t be coding, you should be looking a job as a janitor, or other no intelligence required tasks. No pun intended, but really smarty is that simple.

    Those what i showed along with any other php function ($foo|PHPFUNCTION}, is 95% of what you need. but beware: |PHPFUNCTION you cannot choose params, unless you make your own plugin to Smarty, never needed tho :)

    Reply
  38. Zyx

    pmjones -> why are you using PHP to write the websites instead of C++ or assembler? Don’t say that “no new templating language” is needed, because PHP is not the best solution for a veeeeeeery long time. By “inventing” a new language, you can implement things that will never be possible in PHP, introduce new programming paradigms and more. Unfortunately, neither Smarty nor most of the template engines follow this way, stopping at “packing” PHP loops and conditions into a different syntax.

    Have you heard about declarative programming? The presentation layer does not use complex algorithms. They are quite simple and there are only a few of them – why do you have to reinvent them every time you want to write a template in PHP? Why do you have to invent the techniques of relationship support between the data (ie. categories and products), and moreover – reimplement them every time you need them? Some would say that there are no such template engines, but yes – they are. One of them is even mentioned here and you said that “they’re “more of the same as Smarty”.” Another one is mentioned on the nosmarty.net website.

    I’ve recently had to make a website with views in pure PHP and it was a real pain – ugly code, reinventing the simplest things. I don’t mean URL routing or form helpers, but if there are form helpers, why they are not able to notice that a form field is not only an INPUT, but also a description, title, surrounding DIV. And if it notices, why is it so hard to provide a custom code and you need to implement it with OOP (!!!), where a good template engine has no problems with it? Take a look at Symfony admin generator. It provides you a nice, default layout, but try to change it, you will have to deal with “templates of templates” (sic!) and each controller has its own form layout definitions. With a good template engine that supports the template inheritance etc. changing the layout would be much easier and it would be much more configurable.

    Reply
  39. pmjones Post author

    @Zyx,

    Declarative programming would me more like the XML/XSLT approach to templating; I think the PHPTAL system is similar. This is also known as the “Transform View” pattern, as vs the more common (in PHP land) “Template View” pattern.

    http://martinfowler.com/eaaCatalog/transformView.html

    http://martinfowler.com/eaaCatalog/templateView.html

    Nothing at all wrong with using a Transform View, although I myself have found it to be burdensome (YMMV as always).

    Re “more of the same as Smarty” I assume you are referring to my comment at http://paul-m-jones.com/?p=400#comment-410029 — I am referring specifically to OPT and Dwoo there.

    Reply
  40. SayB

    Honestly, people I know who use Smarty, have a similar psychology to people who are reluctant to use a strict MVC framework (take a hint). Or anything that applies best practices and conceptualization of basic design patterns and their implementation for that matter.

    So if anyone feels nervous / insecure around those who stand for and implement best practices (which is language independent by the way) need to study the fundamentals for software engineering. Frankly, it does *NOT* make you a good developer if you don’t “get” the ideas behind best practices. It only makes you someone who was just as smart how PHP (in this case) is just as easy to adapt as a scripting language. Therefore, re-evaluate before labeling “elitist” to those who actually take the pain to reason.

    Reply
  41. dungiis

    Why don’t you contribute Smarty?. It has been releasing a long time ago. Now is 2009 so, i think until 2011 PHP Frameworks also dies and downs as Smarty.
    – There’s one thing i want to tell you is “‘Cause nothin’ lasts forever Even cold November rain”

    @Andrei you did a good job, anyway :)

    Reply
  42. Philip Snyder

    Nice article! I’ve been looking for something like nosmarty.net to share with my coworkers here. I have never found Smarty to be useful — and once we moved to a true MVC platform, its increasing use has really started to annoy me as it just slows me down and added no additional benefit. As we all know, we can say this stuff until we’re blue in the face but if we’re the only one saying it we often get ignored.

    Reply
  43. Colin

    I recently moved into using templates and I was struggling as to why I should actually use Smarty at all. I understand seperating business/application/presentation layers. I honestly didn’t see how it would benefit me, it’s so much easier to whip up my own little template engine to use. Until I found your article and nosmarty.net I really thought I was missing something fundamental that would make it a good idea!

    Reply
  44. Richie

    Smarty is a wonderful language and concept. I feel there are many here who have either not used it and are repeating from other people (like puppets), or people who have used it, but not in the right environment or in the wrong way.

    There are many situations where Smarty would dramatically increase the productivity of a website build and its future scalability, even in comparison to other templating engines, and indeed (I hear the critics whispering) no template engine at all, or MVC framework integrated – whatever.

    If any of you can find another way to build a site which covers the following as nicely as Smarty does, I’d be impressed:

    – Build a page without regard to the order the components are displayed in
    – Easily be able to determine the contents of the whole page
    – Separate Business logic from Presentation logic
    – Dispell the use of variables used in global scope

    I also looked at the nosmarty website which has obviously been created by people with little credibility and the lack of understanding of Smarty presented by the writer of the website is very limited.

    I would suggest reviewing credible sources like George Schlossnagle (Advanced PHP Programming) whois held in very high esteem, is a contributor to the PHP project and also firmly advocates the Smarty engine.

    If anyone could let me know of any real problems they have with Smarty Id be happy to take that on.

    All I really got from above is a “i dont like” with very little substance.

    Reply
  45. Smarty Crusher

    Nice article, i need ammonition to convince people not to use smarty. Just the fact that people use smarty shows how braindamaged the it industry is nowadays.

    I just had a look at savant: it’s crap.

    Reply
  46. AZS

    Agree with you. Inherited a project that combines MVC & Smarty. & I think MVC would have just been enough.

    Reply
  47. Pingback: o PHP é uma linguagem feia de templates | Blog da Profile Informática

  48. Matt S

    It’s 2014 and they still make updates to this horrible template engine, and we are forced to use it because our ecommerce provider only supports it. Bug ridden still, and horrible to work with. Everything is an assimilation of PHP, I see no real advantage. It doesn’t even have more person-friendly programming style, it’s in fact much more confusing to work with. Can’t believe they sit around accepting bitcoin donations when they should just throw in the towel and stop causing serious harm to the community by pushing a software that will, in the end, destroy whatever business comes into contact with it. Use something that works.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *