Smarty is everyone’s favorite templating language for PHP. It’s great in many ways, one of the main features being that it can display things on a website. It also promotes separation of display code and logic, which many PHP programmers seem to have trouble with: oscommerce, PHPList, etc etc.

So why do I hate it?

There’s no fucking point! All bad programmers write bad code. Why create a language within a language just to force bad programmers to do one thing right? I realize that Smarty does enforce separation of logic from display very well. I’ve used it in several projects. But if its capabilities are so strikingly similar to PHP that for most things there is a 1-1 reference, why bother? Why not just use PHP code?

Also, the plugins (and {php} tag) allow you to make logical decisions, run mysql queries, send rockets to the moon…there’s nothing you can do in PHP that you cannot do in Smarty…which makes Smarty completely worthless for what it’s trying to do.

If you want to promote good programming, you don’t need Smarty. You can rewrite Smarty as a PHP object that sets variables and includes a template. I’ve written this a dozen times over…and it does the exact same thing, except templates are in PHP so everyone can understand them, there is no caching trickery going on, and best of all you don’t need to reference some stupid guide on how to display something in a strange language which you already know how to do in PHP.

So, in summation, please don’t stop using Smarty. It’s a good piece of code for people who don’t understand the basics of separation of logic from display…but realize that Smarty is a hack, a patch, a band-aid. The REAL problem is bad programming, not something inherently wrong with PHP that needs to be rewritten.


OMGOSH 10 comments

  1. I am sharing the same point of view….especially for this “But if its capabilities are so strikingly similar to PHP that for most things there is a 1-1 reference, why bother? Why not just use PHP code?”

  2. Andrew Lyon said

    Well I’m glad I’m not the only one who doesn’t like Smarty.

  3. I am so on the same page here it’s not even funny. I never wanted to use Smarty and resisted until the job I have now where I was tasked to update an existing site. It’s based on Social Engine 3 which is the worst hunk of crap I’ve yet encountered.

    Now the worst part by far is the inclusion of Smarty. I’ve never felt so much frustration in my life.

    I agree: building tools to try to stop bad programmers from being bad is a bad idea! Force them to do good or force them out the door.

  4. Abso-effing-lutely said

    From the moment I saw smarty, I felt the exact same way.

    Now, mind you, ALL template engines are NOT bad. But Smarty is horrible. As you /almost/ point out, Smarty does NOT separate presentation from logic.

    When it comes to template engines, less is more. And when it comes to templating HTML, this is all you nee (indeed, /all you want/):

    1. Placeholders – places which can hold content.
    2. Blocks – templates contained within a placeholder.

    Similarly Your template class should allow you to:

    1. The assignment of values to placeholders
    2. The extraction of blocks as template objects

    (and NOTHING else!)

    Assuming you’re smart enough to allow placeholders to be assigned template objects, /this is all you will ever need/ — and the resulting implementation is fast, simple, and extremely powerful.

    Now, I will do you all a favor:

    This is a sample title

    Chew on that for a second.

    Beautiful site design, btw.

  5. Abso-effing-lutely said

    Above “Favor” did not render properly. Are you SURE you’re not using Smarty…? /troll

    Replace [ and ] with angle brackets:

    [h1][!–%TITLE{%–]This is a sample title[!–%}TITLE%–][/h1]


  6. Thank god someone out there agrees with me why smarty is quite possibly one of the most overrated crap for templating. Just like the author said, WHY IN THE WORLD LEARN ANOTHER LANGUAGE VERY SIMILAR TO PHP, LITERALLY.

    You know what would have been smarter by the stupid smarty team to do is to create a 100% php based templating engine, where the language for the templating is php, and they offer a structure and a set of functions that the user is restricted to use. The templating engine would then just parse the .tpl file.

    Point being, making the user learn another stupid fuken language is fuken pointless. Fuk smarty, their stupid team, and for assholes promoting this overrated bullshit.

  7. yeah , right fuck smarty .
    worthless peice o shit
    syntax doesn’t make sence damn templating sucks
    a developer can do batter than that
    it’s extra bullshit that’s been on the developer’s head now

    fuck off smarty assshit!

  8. {smartyshitload}

  9. What’s worse than programming in Smarty? Inherting an old Smarty project and not knowing WHERE THE FUCK to begin.

  10. Just discovered I need to learn this whole new language when PHP would have been fine. I use lots of functions and includes in my programming and like to set everything out logically anyway, so it’s annoying to be forced to waste my time on this!