Once upon a time there was Smarty!

112 thoughts on “Once upon a time there was Smarty!”

  1. Some people would be very upset by this post I guess. I know lots of people who learned Smart and deploy sites with Smarty.

    But everyone must thank you for being so honest.🙂

  2. And some people always realized that PHP is in fact a template language on it’s own. Why use a template language inside another template language?

    1. Smarty only ends up being ripped back out in the end. There is a thinking among us that when we find something new and curious, we apply it even when it’s a horrible fit – no solution at all – but it’s NEW and seemingly cool! “Because we can, we implement another point of failure”. However, when that developer has made his company a complete mess and frustrates everyone around them, they quit and leave the pile for someone else to come in and clean up. I just got done tearing out Smarty and vBulletin trash that were duplicated all over a web site to do the webmasters tasks because they didn’t take the time to learn about frameworks. When someone flipped a switch in vBulletin – all the sites suffered.

      PHP is easier to learn and less constrictive than Smarty – let your people learn instead of trying to control and limit them. When the rest of us encounter people like you we can’t stand working with you. Life is too short to waste it with a bunch of control nazis. Learn a framework and stop using Smarty.

  3. Ya, smarty is not smart enough anymore. now days, we love to eat cake, we love to ignite our code. but after couple years later we wont be satisfied just with a cake. we will love to have buffet lunch yay !😀

  4. Smarty has excactly one permission to live: If you don’t want template/html/css designers to access php code (and you wanna rely on smarty’s security layer).

  5. If you ever need to give a file to a ‘non-developer’ – I’d rather give them a language that cant be mis-used like pure php. Smarty lets you sort of ‘sandbox’ those people, and then that compiles down to PHP anyway, so whats the diff. I prefer to use Smarty.

  6. Excellent and very valid post. I’ve never liked smarty – it always seemed like there are better ways of separating display logic from page logic than implementing a new syntax.

    Smarty – and similar templating languages – are useful when you want to allow your users to edit the layout of the site or elements on the site and can’t trust the user input.

    I dont really thing that there is an argument for keeping designers away from writing PHP. If they are having to write smarty code, they might as well be using PHP which is much more powerful, and a far more valuable transferable skillset to learn. Otherwise, have them generate the HTML and get a developer to plug in the content. An unmanaged smarty implementation will allow arbitary PHP code to be executed anyway throught {php} code

  7. how about they learn php? its really not that hard. besides if you are allowing designers to create php files, or get in your php code, you shouldn’t just let the software monitor what they are doing, and actual developer should have eyes on it at some point.

    i used smarty for a long time until i realized i wasnt really getting anything from it. i think its actually more confusing than bare php is, plus it has some overhead that you have to be aware of as well.

  8. My (single) reason to use a separate templating language is simple. We allow our users to change their application templates..

    Exposing them to PHP would be a huge security risk

  9. I agree with this article. Those who think that php is to hard to learn for designers or php is a security risk are not up to date of what is possible. Learn the mvc principle and you wont build future applications around a template engine like smarty. Smarty is for people who sit on an idea like chickens on eggs.

  10. Your post is really ignorant and you prove that at least on this topic you don’t have any idea about what you are talking.
    Take it this way: a frontend developer who does just HTML templates might not be aware of doing if (isset($var)) echo $var;. Instead they use smarty {$var}, which does the isset stuff for them. Or he might not be aware (and he should not be aware) of doing “if (isset($array)) and is_array($array)) { foreach ($array as $key => $value) { …} } else { …}”. Instead he will use {foreach from=$array item=item key=key}…{foreachelse}…{/foreach}. So Smarty is not outdate, it has in fact a lot of glitches I do not like but it is a good solution when you have a business process where the creation of the HTML templates are not done by the developers. And yes, there are guys out there who are much better in writing HTML (including nifty semantics, microformats, fixing browser glitches) than most of the average developer.

  11. Take it this way: a frontend developer who does just HTML templates might not be aware of doing if (isset($var)) echo $var;. Instead they use smarty {$var}, which does the isset stuff for them.

    So the developer says toe-may-toe instead of toe-mah-toe?

    So, you’re saying that it’s not OK for these mythical frontend-only developers to recognize PHP syntax, but OK for them to recognize Smarty syntax. Honestly, is one really different from the other?

  12. @Lars

    If a designer can learn such a complex scripting features of smarty then why the hell they cant learn only for-each, if-else and echoing in PHP which really helps them to upgrade?

    And I dont think there is truely any single template designer who knows smarty but no PHP! Smarty is not HTML, Smarty makes it almost like another scripting language.

    I dont agree with you, Lars.

  13. I’m too much of a fan of modifiers and post filters in smarty to say that it can be replaced that easily, its far too easy to forget to escape something if your not using a templating language setup, personally though im TRYING to migrate myself to phptal, its taking some work though as iv used smarty for years now myself as well… such an odd syntax when you compare the two🙂

  14. I liked this post! Excellent! I never found Smarty useful – there are much better ways to separate the display logic from application/business logic. IMO, using the good old MVC pattern is much smarter, simpler and easier than implementing a templating engine.

    He is dead, God bless his soul!

  15. Smarty is indeed very useful when the templates of an application are going to be edited by non-developers, or 3rdparty developers. I know that it is almost like a new scripting language, but yet it is quite more simplisitic then pure PHP. I do not agree that HTML designers can learn PHP’s basic stuff like “echo” or “foreach”, and to prove my point I’ll say to have a look at WordPress themes. They have PHP as their template engine, and the designers are very good at copying the already existing PHP stuff in the templates, but it is very hard for them to add new stuff on their own.

    Another advantage of Smarty is that it acts as a security layer. Its “almost like a new scripting language” syntax acts as a sandbox from performing malicious deeds when in “PHP land”. Here is an example – I can put php code in a WordPress theme that deletes all the records in the DB of that WP installation. Any 3rd party developer or designer creating a new theme/sking for your application can do that, right ? So how can you prevent something like that ? It is very easy w/ Smarty – you just can not do that🙂 You see, this is the problem with pure PHP — it is both simple enough for basic stuff like echo’s and foreach loops, but in the same time it is powerfull enough to screw up a lot of stuff. That’s why Smarty is an excelent solution for any application that offers “outside” developers to do new themes/skins. In the same time, if you are doing an application that does not have such a feature and you as a developer do all your HTML templating, then you cna use whatever you want – whatever makes it more easier for you: plain php, smarty, savant, whatever🙂

  16. @Kaloyan

    If you can write PHP code that deletes tables from a DB in a wordpress template, that is also true for smarty templates. Your template designer could be enough smart ass to write a hook (or filter) and cause a disaster.

    Smarty doesnt reduce the risk in such cases.

  17. Lars Strojny your post is really ignorant and you prove that you know nothing on the subject. Seriously, don’t check if a variable is set in your view, if a variable is passed to your view then you’d better make sure it’s set in your controlling logic.

    And your claim that front-end developers shouldn’t be aware of basic PHP code is down right insane. You work in an industry where technologies mix together more and more, it’s impossible to do any serious website these days without knowing both HTML, Javascript, XML etc. And if you know javascript then you can damn well learn basic PHP too.

    This isn’t 1992, there are certain standards developers have to be held to, and such a thing as front-end developers doesn’t exist in any serious business; the fact that you even seem to think so scares me, hopefully there aren’t too many with the same thoughts.

  18. Hasin,
    You’ve managed to hit the nail on the head with this one. I’ve been a long time user and supporter of Smarty, especially when utilized in non-framework environments. At my workplace often we have folks that do not know PHP making modifications to code. Thus far, I’ve been able to train them to leave stuff within {} alone. However, as I begin to utilize the various frameworks, I’m finding the good old PHP method as well as the various Helpers that are available in the Frameworks as being beneficial.

    Lately I’ve been using the Zend Framework, and have realized that incorporating Smarty is basically pulling double duty. Sure I have devised methods to utilize the View Helpers through Smarty, but it seems to cause redundancy that is not necessary in the Framework environment.
    Now, if I have a simple (non-framework-based) site that I’m putting together, I consider Smarty. But, as I get further into using the frameworks, I’m finding it more laborious to use.
    It’s great to see that I’m not the only one feeling this way.

  19. After using Smarty for about 1.5 years I realized that it is something like taking the longer route to your destination than the straight forward route. I completely agree with Hasin’s reply to Lars comment.

  20. I agree that Smarty is not state-of-the-art anymore, and with those new MVC enviroments we all can develop complex applications much quicker than we used to some years ago.

    The cool thing about Smary is, I never had the feeling to actually have to learn it. After installing, just divide application and visualization, then go for it. No need to learn a new trade, just go for it. And that hasn’t changed since now.

    Therefore my opinion: Smarty is still a good and clever way to do that kind of programming, if you don’t use a MVC framework.

  21. I think Smarty is still very valuable. Mainly for the designer argument.

    Many people on here are saying there is not much difference between having to learn Smarty syntax vs. PHP syntax.

    From much experience, let me tell you, for a non-technical person, there is a BIG difference between {$var} and .

    The less syntax the better.

    A lot of it is based on how your team is structured. Do you have a separate graphic designer, front-end developer, back-end developer? Then you may not need Smarty. If you only have a graphic designer and developer, then Smarty comes in handy.

  22. Bravo, Hasin!

    If you’re going to make designers learn a language (as you are when you’re endorsing Smarty), why not make them learn XSL or JavaScript?

    At least those are “real” languages, and have some usefulness outside of the small box that Smarty-thinking puts one in.

  23. No-one is mentioning caching, the best feature about Smarty is the caching. It’s all very well to say you should write better more efficient code but if you have a very high traffic site and need to perform complex queries, you can run the page once and then spit out the cached version based on any parameters you want. That makes page rendering very fast. Smarty gives you the control to do this on an entire page or just bits of it.

    If on the other hand you are generating simple templated pages with no traffic pressure, then yes Smarty is probably overkill.

    I dont think it’s a matter of Smarty being the right or wrong thing to use, it’s a matter of picking the right tools for the job in hand, and yes sometimes that is Smarty.

  24. well, ok,really, how much time do you really need to learn that {$foo} does same as echo $foo ?🙂

    It took me about two hours to figure out the basics of Smarty, and after first 2-3 days I already knew everything I needed (and it was like 95% of everything I ever needed from Smarty syntax), so I think that “the need to learn another syntax” is really not such a big deal a you present it.
    And you get syntax that uses less ()[]”” characters and, in case of a bit more complicated expressions mixed with HTML it is much shorter and clearer than echos, IMO. Plus smart editors support the syntax highlighting and even code checking for Smarty, which is not the case with html inside echo statements..
    Also pre/post compiling filters are very cool thing, you can’t do that easy with plain php..

  25. Lately I have been contemplating the next logical progression for moving away from using Smarty.

    I have previously used templating systems before Smarty (patTemplate) and have discovered that actually using a templating system slows down the development time and accumulates more code.

    The only reason I ever used Smarty was to separate my php code from my design, not because I needed other designers to work on the templates but to keep my code tidy and maintable.

    Though I still believe the following is true:
    MVC > Smarty > Plain PHP files

    The MVC concept is a huge improvement over the templating solution as many have pointed out, less overheads, more flexability (the pure power of PHP itself) and no need to learn any extra syntax.

    But using a templating system is still better than using PHP mixed with html with no functions or objects (mainly because its an absolute mess!)

    Also the purpose I loved about using a templating system is suitable for small projects, the big boys like Cake and Igniter are a bit overkill (others may argue in defense of this) but a simpler MVC would be more ideal for the smaller frys.

  26. Hasin, if you hate Smarty that much, why do you still receive money from book sales?

    Why don’ you share with us how much money did you earn?

  27. The only reason for using Smarty is to stop programmers being tempted at doing advanced php-stuff which should really be done in the controller. and the {php} option can as you probably know be turned off to keep it safe from clutsy developers.

    However, I agree with you that there is no point in having a different syntax than php in the view. But until we can limit what types of php-calls that can be tone in the view, I think we have to stick with a templating language like smarty.

  28. Please note that a Template Engines and MVC Architecture answer two different questions. Sometimes you need to use Smarty with an MVC-Framework.

    For example, in a Blog Provider system, your users may want to change their blog templates. You can’t use pure PHP in these blog-templates.
    That’s not safe. Template Engines are designed to solve this problem.

    If you’re going to allow everyone to access to your “view” files, then you need a Template Engine.

  29. Josho – The term seems interesting “ES – Expertise Syndrome”. I was familiar with “MAD – Multiple Ambition Disorder”

    So what is ES? Can you help me the understand that?

  30. True, Smarty is completely useless. People with little or nothing programming knowledge will argue or deny this, like they are doing here or in other blogs or forums.

    To all the designers or junior developers that support Smarty, my advice is to follow the steps of more experienced programmers, like Paul M. Jones (he posted a message above). If the guy that wrote the template engine that Zend is using tells you not to use it, don’t use it. And if the guy that wrote a book about Smarty tells you that it’s useless, guess what, right, it is useless.

    We, programmers, cannot keep arguing with web designers or web developers about this stuff.

    Happy coding!


  31. It is just so funny to hear developers talking about Smarty and template engine without any caching considerations.
    It is one of the purpose of such a langage, and we also avoid to use long <?php … tags that annoys the reading of HTML.
    Besides MVC doesn’t bury templating engine at all, or you didn’t get a bit of what is a MVC (you need to write views, and they can be in Smarty for instance).

  32. Once upon a time, there is one man who hate smarty because he think Smarty is too big for just a template engine. He think what’s the point to learn Smarty language if he knows how to coding with PHP. He always work alone, so he always think template engine is just for ‘team works’. Then one day, something happen and forced this man to learn Smarty template. Suddenly this man realized that by separating business logic with Smarty, he can create more and more website faster than he ever create. He just need to create one business logic for login page, registration page, news page, gallery page, etc and with that business logic page, he can create another website project just by redesign its presentation layer. Maybe he still hate smarty because Smarty is too big, but deep in his heart, he admit that using Smarty as his template engine is always worth something. Now he live happily-ever-after in the land of PHP-far-faraway. Moral of the story: For someone who never know Smarty, it’s their choice to learn it or not. For someone who already know Smarty, it’s their choice to using it or not. We never know what’s the meaning of ‘sweet’ or ‘bitter’ if we never tasted it. We never know if ‘black’ is our colour if we never wear it. Who knows if Smarty is worth for someone?

  33. I’ve been using smarty for several projects over the last 3 or 4 years. First it was the separation of PHP and HTML code that seemed most important for me. Now it’s also reusability of easy to grasp code snippets.
    During the last 2 years I’ve basically developed my own MVC framework, strictly object oriented and quite powerful. It’s probably not as big as Cake or Zend or whatever, but it suits my application and it is efficient (both in development time and application performance).

    When designing complex page layouts I don’t know what I’d do without HTML syntax highlighting (including smarty syntax, thanks to phpEclipse). It’s just more convenient and less error-prone.

    And there is one more thing for MVC concepts to consider: once you use smarty you are forced not to use PHP code inside your page (well, as long as you don’t use {php}{/php}). Thus you can always be sure that your MVC concept still holds. I’ve split my templates in quite a lot of snippets for re-use (e.g. all the form stuff) and I can always be sure that there will be no inline php code doing anything weird. Can you be this sure when calling functions or including other php files instead of {include}-ing a template file?

    I understand what the original author is saying and why. But I think that smarty _can_ be part of MVC, and if you do it right, you get clean code that is easy to maintain and less to type than traditional php/html code.

  34. PHP frameworks is kinda new for me, but doing more learning and reasearch it seems that it’s even more complicated, very limited, same old php coding with some presets, so IMHO smarty is the best choice for CSS/xHTML coders, it’s straight forward and keeps designers out of the code, that’s what developers want init😉

  35. I love smarty, and have spent a lot of months in it. I respect the way; it is not a template engine. Better call it to have a different programming and presentation.

  36. I’ve been using Smarty in the last 2 years.

    You says “Why learn a new script language for make views?” or “But is there really any designer who knows only smarty and no PHP?”

    If you says that I’m concluding that the designers have to learn PHP (or ask for help to developers). OK.

    Now, it’s simplier for a designer learn:
    echo trim(str_replace(‘#’, ‘@’, htmlentities($text)));
    instead of:


    I think if any designer needs to learn some scripting language for make templates, it’s easer Smarty than PHP. Why? because Smarty it’s an extension of PHP. A friendly user extension of PHP, why it’s the simpliest for a designer learn all of string functions in PHP if in Smarty are very simplier modifiers?

    It’s easer for a developer too. In my case it is! Why I’ll develope an app using only PHP for templates if I have an API like Smarty that help me with my templates?
    Develope my owns PHP functions, my Helpers to help me in my templates it’s another discussion. We’re talking what is easier y simplier for use or learn.

    Now, if you guys want to talk for quality attributes for our apps using Smarty like performance, it’s another discuss too, and I’m completly sure that it’s better use only PHP functions that Smarty, of course.

    Sorry for my english.

  37. I believe as a designer that the engine is good for seperation from a developers point of view only i.e. when selling closed source scripted php you can still allow for customers to edit the theme and layout but not the function. (albiet they need to learn how to use smarty syntax first)..this can be quite daunting to someone who doesn’t know or recognise programming syntax and how it works. For me personally I do not wish to learn smarty above php. Learning simple php is as easy as learning html/css, learning OOP is a much more time consuming difficult task that requires focus and dedication. If I where to step into programming PHP would be my choice like millions of others for obvious reasons. I also believe php is the (cryptographic) key to smarty once you have learn’t php smarty is simple, not true vice-versa.

  38. Aren’t smarty templates ‘safer’ than direct PHP? Building a user configurable system that allows site maintainers to upload templates without worrying about rouge code with system calls and embedded database commands.

    It would seem that this Smarty or an advanced template system would be a valuable addition to applications with user configurable views.

    Am I missing something?

  39. Fyuh…
    I’ve heard smarty once. But never learn it. Now I’m learning MVC Framework, but really confused on choosing the right one. The candidates are Zend, Cake, & Tigermouse. The latest is based on smarty template engine. While Zend & Cake have their own template syntax and not recommended to incorporate them with smarty. But this article and the comments posted by all of you folks really give me some pictures about the developer realm world wide. Thanks you folks. So, now I will focus on learning Cake, and waiting for the other great framework. Tigermouse is lack of documentation. I’m not succeeded installing Zend. IMO, framework make coding more “fun”. Thanks to Hasin and all folks.


  40. Who really cares? I like Smarty, you don’t. Some people like Windows, others Mac. Its all preference and whats needed by the current task at hand. It took me a total of 30 minutes to skim through Smarty’s tag documentation and grasp it. Its pretty much an advanced form of using BBCode in forum posts. BBcode can be done in HTML, but forum moderators do not want users being able to do that, so BBCode exists as a sandbox.

    And yes, there ARE successful companies with job openings for both “HTML only” people and “PHP only” programmers. In a truly successful development environment, everybody is specialized at their job, and one person stepping on the toes of another is minimized.

    1. Seriously? Did you ever coded in PHP? I don’t think so. Your php version is wrong. The closure tag is ?> not ?php>. And by the way, have you ever heard about shot tags? Do you prefer {$headline} with the slowness of Smarty and the syntax no one else uses, or with the simple and fast PHP?

  41. Smarty had a big disputes in here. Just look at my website, how many projects I might have completed with Smarty. In a small business, it does not satisfy you, while in large business, your designers are likely to play your codes, and NOT USING Smarty could be a loss to you.

    Use only if it supports your needs. My suggestion is to use it if you have started developing a project even without a final design, it helps. And in other cases, you can created advanced-theme-able projects with this third party tool.

    Try to find out a better hosting server to give you a little more memory for empowering the performance of Smarty.

    Good luck with it.

  42. I am a php developer and have been given the job to work on a site that uses smarty. This is the first time that I’ve had to use smarty and I can guarantee that it is USELESS. I cannot write useless in big enough text.
    I believe in separating logic from presentation.
    I believe php is a templating language.
    I believe in making things simple for the designers that create the templates for my web sites. The designers have learned sufficient PHP to do what they need. Smarty is another language to learn and it is painful. PHP does it so much more efficiently. If a designer can learn Smarty then they can learn the PHP that does exactly the same thing. I have seen designers learn PHP (the little bit they need for templating) and they feel empowered. Any responsible designer will stick with the code that is required. If it’s necessary to block a designer from using PHP then you’re not trusting them so do not use that designer. PHP for templating is easier to learn than Smarty.
    Smarty is a waste of time. Sure there are people that know it and use it. I have no beef with someone using something that they’re comfortable with. I do suggest, however, that anyone new to the website business is far better off learning the tiny bit of PHP that will get them creating templates. What I would prefer to see instead of Smarty is a site dedicated to the templating features of PHP. It could show the php for each of the Smarty elements and for the Smarty helpers it could show the helper functions from the various frameworks out there.
    Maybe there was a need for Smarty in the past. I did look at it (very briefly) several years ago and wondered why anyone would use it because PHP is so good at templating all by itself. I stuck with PHP and the designers I work with have done the same.
    I just did some looking around for problems with smarty and there are quite a few sites dedicated to the subject. I think that’s enough evidence to prove that it’s a waste of time.
    So to sum up, if you’re new to web design and you’re interested in PHP then learn the simple PHP that will get you templating. Do not learn Smarty. Smarty is like learning anything proprietary. You are stuck with a limited piece of knowledge that can’t be used anywhere else. Learning PHP will broaden your horizons rather than narrow them.

  43. Smarty is complex and hard to learn from zero but it is easier to learn than PHP. Just like PHP, hard to learn from zero, but easier to learn like JAVA.
    Bit it seems if you don’t know Smarty you agree with Hasin, but most of the guys who know very well, they like Smarty very much. I recommend you guys to learn it and use it in a large project and your programming style will be changed forever.
    BTW I don’t think it is the same thing:
    echo $PHP_SELF and {$PHP_SELF}. And yes, the graphic guys can learn Smarty as they learn Flash Action script but they are graphics so to make a nice and secure code is not so joyful like for the developers so they can copy/paste ugly tabulated cycles as they want. I’ve found this article because I was looking for another templating system but I think this article is a pretty good advertisesment for the templating system, maybe not for the Smarty.

  44. Am I missing something?
    This very day I put out a post on Drupal’s theme forum here http://drupal.org/node/317370
    advocating for Smarty to be made the de facto templating engine for Drupal.The PHP code in the phptemplate engine was driving me crazy.

    And here I come to this dude’s site only to read this (not so clear) argument against Smarty.
    FWIW Smarty works.Period.After working with ASP.Net for 5 years and Smarty for 4 years (not to talk of JSP stints), I can affirmatively say Smarty works and rocks.Combined with the ZF, you have a robust combination for implementing MVC web sites.
    Hasin pls clarify whats the advantage of manually generating HTML from PHP code as
    opposed to Smarty’s dynamic placeholders(and filters+plugins)?


  45. I have to agree with this article. Now that PHP is being used to build enterprise solutions we to look at new ways to solve the designer/developer issue.

    We experimented with a unique idea using php5’s new DOM module. And all the designer needs to be aware of, is three new attributes ‘VAR’, ‘CHOICE’, ‘REPEAT’ they cannot change anything else leaving the logic to the developer and design to the designer. So fare I have had over 15 designers use it and all have walked away happy with the development environment they used. It allows for designers to use dreamweaver/photoshop apps for designing without having to see one piece of php code.

    After having great success with this system locally we have now setup an opensource project so get the response of the public: http://www.domtemplate.com/

    Maybe this could be the next generation of template engines.

  46. Nice to see a topic like this getting so much response. I’m not going to give you my thoughts on this, I’m just going to say this:

    If you are a self-respecting developer, NEVER… EVER… say the following when you are pointing out the cons of Smarty:

    ,,[…]…Seriously why the hell I need to learn a new templating language when a “echo” does the thing much better. […]”

    Well… If you’re too (…) ignorant to understand what Smarty is actually meant for and how to use it, don’t try to make your point by using arguments that are irrelevant to it’s nature.

    Let me try to explain myself:
    Imagine: in a kitchen there is a table with two tools; a ninja-sword and a breadknife.
    I want to slice a piece of bread off a breadloaf, which tool should I use?

    You: “Use the ninja-sword, it’s much faster and easier! You might split the table in half, but why care about the mess in the kitchen? I’m eating the bread in the living room!”
    Me: “Use the breadknife, that’s what it’s meant for, it will do the job without messing up your kitchen and keep the table undamaged”

    kitchen = building block of your application
    table = your code
    breadknife = using Smarty’s {$foobar}
    ninja-sword = using PHP’s echo $foobar;
    breadloaf = certain data you need

    Anyone who suggested that Smarty isn’t useless, but is in fact one of the many tools available to you, I agree with you!

  47. Very, very odd to read a comment from somebody who has written a book about a subject and really does not seem to have the smallest clue why it used and what it is good for. The small hint about the cost of “parsing templates to PHP” reveal that the writer is either totally ignorant about the technology or deliberately wants to spread false propaganda. How long did he actually USE Smarty? Long enough to write a book and the cheat sheet?

    My company has used Smarty in hundreds of applications and we will continue using it simply because it saves an awful lot of time. Having trained a bunch of PHP people to make basic use of it takes just one day. One single day.

    My designer simply loves Smarty, as well. It allows me to give him a rough idea about the site using the only horrible table approach I am good at and he can change it to nice DIV based structure and valid CSS in no time. He is very good with PHP but he is not the least interested in having a look at the PHP code.

    The “V” part of MVC is not simply CSS as the writer is telling us. It is valid (X)HTML as well and we use Smarty to build the structure of an application and format it using CSS.

    A good designer should NOT need to learn ANY PHP. A designer is good at graphics, (X)HTML and CSS. There are some rare exceptions like my designer, of course. The bottom line is that if one finds Smarty useless in a developer/designer co-operation he has simply got everything totally wrong.

  48. @SM: Sorry, i couldn’t be agreed with you, and felt like leaving a comment here. your company has uses smarty in 100 apps, thats cool, but if i was in your company i wouldn’t make it “future” anymore. why? why wouldn’t i try something that gives me better and easier solution? i would ask my developers to know what is call MVC(design pattern thats being widely used…u know right?) and how its separating the logic and presentation. i’m sure i wouldn’t allow them to eat the same fish everyday just because they have to fill up their stomach. rather i would tell them to taste something different while they are filling the stomach.

    and why the author fill the guilty to right this post just cuz he wrote a book on Smarty? i disagree..indeed i thank him for his honest comment.

  49. Why does everyone insist on comparing MVC frameworks with Smarty? Smarty is a template engine, not an MVC framework. It is more comparable to the “View” element of an MVC framework. As a matter of fact, many people have integrated Smarty as the view with CodeIgniter, Zend Framwork, etc.

    Smarty was initially built upon a single purpose: to insulate the web designer from the application code, and provide clear separation of presentation from business logic. Yes, the latter can be done with PHP alone, but not without a lot of legwork. Every other feature of Smarty is surrounding this purpose. If you do not have a purpose for clear separation of template/business logic, then Smarty may not be the best tool for you.

    I’m also going to add that the Smarty book is mostly fluff. There is not much meat to the book that you can’t get from reading the Smarty manual. It is basically a regurgitation of the same information. The content of the book and the content of this article clearly indicate the limited knowledge of the author.

  50. The last comment sums it up perfectly. If the book is the same one that I was asked to contribute to, then I imagine it was a lot of fluff.

    When I was shown the chapter list, it was obvious that those writing the book had nothing to add over the manual and were just trying to get a book out because they saw Smarty as a popular product with some potential books sales in it. They certainly weren’t demonstrating any effective implementations or anything, hence why I declined to contribute.

    Smarty is certainly not dead. The code looks dated these days, but version 3 will certainly clean that up. Whether one should use it, or any other template engine, is really a matter of preference, and whether there is an actual need for this separation.

  51. Thanks Lars Strojny, SM, smarty comment, mitch

    This post is absolutely ignorant and provocative.

    “Smarty was initially built upon a single purpose: to insulate the web designer from the application code, and provide clear separation of presentation from business logic”

    Well summarized.

    Smarty is certainly *not dead*, I may agree to call it bloated and outdated but the templating synthax
    is intuitive for both designers and developpers and is certainly still very relevant.

    These types of blog posts are absolutely unprofessional, sure you can express your opinion but explain in *WHAT CONTEXT* something is *USELESS*.

    According to the author, all of these are useless: “http://en.wikipedia.org/wiki/Template_engine_(web)”

    1. Again, there’s no need to offend the author. He is just writing down their thoughts. And by the way he is right in my HONEST opinion. It’s not about comparing template engines vs frameworks, it’s all about understanding that with TRUE MVC frameworks Smarty has no need to exists except in some rare cases nowadays.

  52. Hi, I agree with your article. I have suffered with smarty templates (www.nosmarty.net for more details) . With existing frameworks, it is not necessary to use as templates for the same separation of the hearing, but if necessary use, I prefer phptal or phpsavant. Greetings

  53. Al, given between

    {capture assign=”foo”}{my_helper var1=”bar” var2=”qux”}{/capture}


    myHelper(‘bar’, ‘qux’); ?>

    which one do you prefer?


    {assign var=”foo” value=”bar”}

    is certainly less readable than this

  54. I have been coding Zend Views for a while using HTML, CSS, Javascript, and PHP directly.

    The argument that PHP is to complicated is out dated. It has been a long time since I have hired a designer that didn’t know Javascript and PHP (or RoR).

    As others have pointed out, Smarty or another template engines are appropriate for providing end users the ability to customize some part of the application.

    But it does not follow that the rest of the application should be rendered using Smarty.

    The Zend_View provides the flexibility to render some of an applications view’s directly in HTML/CSS/Javascript/PHP and some views with Smarty. This would be my recommended approach.

  55. The greatest advantage of using Smarty is its caching! Some guys already mentioned that above and I’d like to emphasize it once more. How could that feature be completely ignored by a Smarty book author? Come on!

    But also the templating is very convenient once you’ve learned the syntax. I’m using Smarty + Caching on some medium traffic sites serving some ten-thousands of pages each day, querying the database up to 60 times per uncached page view. Thanks to Smary it’s very easy to apply caching to specific sections on demand, and to adjust the caching time and behavior just on the fly. Changing the page design on the fly is very easy with Smarty, too. Beyond that it feels good not to touch the PHP files every and each time I’d just like to change a css style declaration or rearrange the information.

    Perhaps a good point is, Smarty is hard to learn for webdesigners. But it’s a good tool for developers. Finally all depends on who uses it and for what it’s being used.


  56. Whilst I can see the argument for the use of Smart, I have just taken over a domain which was built using Smarty and I am now on the point of giving up and rebuilding it from scratch.
    I am not a PHP guru or (by any stretch of imagination) a “programmer” but after many years of practical work with HTML , very basic PHP and packages such as Joomla, WordPress, Flash and straight HTML, I really can’t see the point of having to learn a new protocol just to amend a template. I have tried to get to grips with trying to add SEO to the Smarty templates but with total lack of success – I can’t understand the basic interconnecting linkages making the end product. At least the online PHP documentation and Forums give quality assistance when needed and one can work out quickly if the task is too advanced to be taken on and hence handed to experts. In order to add some SEO to the domain I would need to learn Smarty from scratch – no thank you.
    When you do a “View Source” on the page it looks like standard code hence I waded into this problem with my eyes shut- next time I will check deeper.

    Fred – designer and non-programmer

  57. I am surprised at the blog authors’ claim that modern MVC frameworks make Smarty obsolete. One thing to note is that both CakePHP and Symphony frameworks predate the authors’ book. But I guess the author might have missed those while been busy working on the Smarty book. Nice book by the way. But back to the topic, I must say that Smarty cannot and should not be compared to modern MVC frameworks. However, it can be integrated into those frameworks and be used for presentation or “view” layer. In fact, Smarty might have found itself a new purpose in serving as a template language for “views.” Not that you have to use it, but it is there, together with all of its features if you feel like you do.

    From the comments I see here, Smarty doesn’t help designers very much. People without programming experience will probably find learning Smarty, or any other programming language for that matter, a frustrating experience. This is especially true for people who feel they shouldn’t be doing this in the first place. I am a developer, and I wouldn’t be happy if I was forced to learn graphics design. On the other hand, for programmers, learning the Smarty language will not pose much of a problem.

    As for the overhead part, yes, Smarty causes some additional overhead, but not as significant as some people (not familiar with how Smarty works) imply. Smarty parses its template files only once and compiles them into PHP files. Unless the template files are modified, no extra parsing occurs. Of course the PHP files do contain “extra” code, but this is why you don’t have to worry about calling isset() on every variable, in your presentation layer, before using it.

    Personally, I find Smarty’s syntax and the “hand-holding” features convenient. I think my HTML looks somewhat cleaner, at least to me it does. I use Smarty in conjunction with CodeIgniter and am really happy with how it performs. So a simple answer here is that if you like the features that Smarty offers, then go ahead and use and if not, then don’t. Smarty forces good coding habits by giving you limited access to PHP functions (when used with default settings), so that your presentation logic is well separated from everything else. So in the end it might just be more useful to developers than to designers whom it was supposed to assist in the first place. On the personal note, I am yet to see a small or medium size company utilizing separate divisions of Web developers and Web designers. Just look at some of today’s job postings. You’ll be lucky if they don’t ask you to do a graphics design as well. To put it simply, Smarty is a technology that might not be preferred by everyone, but it is by no means dead.

  58. Agree with this article, I have no reason why I use smarty. For simple things I have to google to find how to do this in smarty for no reason when I know this in PHP. I thik Savant is the best and easy to use template system.

  59. This whole article is complete propaganda. Smarty separates business from presentation, and insulates the view from the business code with a simple tag syntax. If you want to open up your views to third parties without concern for PHP abuse, Smarty is perfect. If you want a clean tag syntax instead of the rather unruly syntax of PHP in your view, Smarty is great. If you don’t care either way, if your developer is your designer, if you prefer straight PHP, then don’t use Smarty, and don’t cry about it either. I think a lot of people here crying wolf either don’t understand the real purpose behind Smarty, or have picked in the middle of a project where Smarty may have been implemented poorly and got a bad taste about it. Smarty has saved me countless development dollars through the years, an lest we forget, it is FREE.

  60. I think he is right when using MVC because in MVC you have a separation of logic and design. I use Smarty for a very long time and I am a big fan of it. It is very helpfull if you don’t use a MVC-Framework. I don’t think that smarty is dead. You have to think about the size of your project and for a small project it will be oversized to use a MVC-Framework. Smarty will be a better alternative.

  61. I would have felt bad if I had bought your book on Smarty! I wonder how much php changed in those 2 years that you could not foresee that smarty would be redundant. After all, Code Igniter started way back in 2006!(when you wrote the smarty book)

  62. That’s just stupid…. The point of using “things” lie smarty is
    1st it support caching
    2nd it’s not that complex as other fameworks (for example Zend the biggest sh1t ever )
    3rd it’s standardizing the way of developing websites. (if a few people are working on one project simultaneously and everybody is doing the things his way then the result is a complete mess)

    1. 1 – This is needed because Smarty is low as hell.
      2 – Smarty is a Template Engine. You can’t compare the complexity of a template engine with the complexity of a framework. You may wanted to compare PHp and Smarty. Yet the PHP syntax is pretty much the same as the Smarty one.
      3 – This is true also for clear and simple MVC. Still, no need for Smarty.

  63. you have no idea what you’re rambling about. it’s plain to see you will never understand what is smarty and what is mvc.

    some of the comments are just clueless too. lot of beginner-ish talk just like the author.

    hint: wordpress

  64. Whatever framework that you use, you can fully isolated the developer from designer. The developer still needs to massage the designs received from the designer to make them function and meet requirements. We all need to continue to work together!

  65. Agree with “thelonegunmen” and “lars”… the author and others do not realize the benefits of a templating engine like Smarty. With experience, they will get there.

    I just migrated a medium-sized website to CakePHP. The server-side is totally re-done. However, Smarty code is barely touched!

    Really wish CakePHP incorporates Smarty in the future!

  66. I think that is among the most significant information for me. And i’m happy studying your article. However should observation on some basic things, The web site style is perfect, the articles is really nice : D. Just right process, cheers

  67. I think after all Hasin was not so wrong.
    Smarty v. 3 come out and not much has really changed.has it?
    Wordpress, joomla, Drupal and other all doing well without smarty. Sure Prestahop is gaining momentum in the ecommerce arena and they use smarty. I understand that part of the community is pushing toward a smarty-free in there as well and who knows they will get that in the coming versions of PS.

  68. I 100% agree with your article, why learning a new language when everything can be done in Plain PHP? You can even use a lightweight PHP template engine if you need to separate code and design. phpSavant is a great alternative to Smarty, but the template class included in phplib is ok too….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s