Why template systems like smarty are useless and sometimes bad


Because there is a learning curve, because most php template classes have their own tags or even their own language like smarty and because they are very slow.

I know that many people say that template systems are useful, but others say that they are useless piece of code.

I must agree that they are indeed useless

Why ?

There is a long list of cons:

In most php template system you must learn another "programming language" or at least some weird tags, take a look at some smarty syntax.

{if $name eq 'Fred'} Welcome Sir. {elseif $name eq 'Wilma'} Welcome Ma'am. {else} Welcome, whatever you are. {/if}

What is the reason of writing that piece of code when you can write this code in plain php?

<?php if ($name == 'Fred'} { ?> Welcome Sir. <?php } elseif ($name == 'Wilma') { ?> Welcome Ma'am. <?php }else { ?> Welcome, whatever you are. <?php }?>

Their argument? It is easier for a template designer to understand the first piece of code.

So I ask, what is so hard to understand the second one ? does "<?php" tag scare so much ?

This is the first argument, there is a learning curve, you must learn additional programming language.

The second argument is that templates are slow, they are big classes with lots of code, that parse "templates".

Smarty is an interpreted language inside another interpreted language "php" so your files (templates) are parsed two times.

Now "smarty people" will say that smarty has a cache feature that transforms smarty code to php code and this makes it faster.

The question is, why not write php code directly ? And for the caching of the page part, there are so many cache solutions these days, like APC or eaccelerator or commercial ones like Zend optimizer, and you can also have caching directly with a php class

The only use of templates I guess is in a system that you must use "untrusted" templates, that you don't wish to contain code that can harm your system, but in this case a clever apache,php configuration can do the trick. You can use php.ini to disable some of php functions and allow only basic stuff needed by templates by adding the following

disable_functions = readfile,system #and the list can continue with other functions that you want to disable separated by comma

You will probably ask what to use in order to keep your php files clean, without any html. You can use a MVC framework to separate your presentation logic from your bussines logic, in some words php from html.

Some popular MVC (model view controller) frameworks are: Zend Framework, Symfony, Cake php and some others just search it on google

Share this with the world



Michael Phipps

I'm a long time user of Smarty Templates, but I've gotta say you raise some really good points. Why do I use Smarty? To separate business logic from presentation logic. It used to be so designers could work with me, but I end up having to create the template myself anyway because web designers don't understand templates.

I don't like having any HTML inside my PHP code. Even though, unless you enforce it, Smarty still allows PHP code in templates - and one project I worked on I found another developer just writing PHP business logic straight into the Template Pages... What's the point?

With the way I use Smarty, there's really no reason for me not to use plain old PHP instead. In some cases I've used some pretty complicated template instructions to achieve something that would be much simpler to write in PHP.

I have considered dumping smarty in the past. Maybe it's time I actually tried working without smarty on one of my sites?

Posted on 2007-11-19 15:51:27

Hi Michael, if your templates are not made by a designer, but by someone with php knowledge, I don't see the purpose of using smarty. I think that a designer's job is to make the template in psd or other graphics format, and the front end programmer should make the html + css from that template and finally a php programmer should include the necessary php code to the template.
I think this approach is the best, because everybody does what he is good at.
I think is a very good idea to dump smarty, because there are no advantages in using it. You can try a template system based on php like <a href="http://phpsavant.com/yawiki/">phpsavant</a> or you can try a full featured mvc framework, the advantage of mvc is that it keeps your code really organized, keeping your business logic separated from your presentation logic.

Posted on 2007-09-30 22:01:48
ion gion

There is indeed no purpose to use any template system in php. PHP itself is a template language, for example you can write the code above like this:

&lt?php if($name == 'Fred'): ?&gt;
Welcome Sir.
&lt?php elseif: ?&gt;
Welcome Ma'am.
&lt?php else: ?&gt;
Welcome, whatever you are.
&lt?php endif; ?&gt;

Remember that PHP also has an alternative syntax(so you can dismiss those curly brackets )


foreach($items as $k=>$v):

and the list goes on(for/switch/do/while ...)

PHP itself is a fully fledged template language.

Posted on 2007-11-19 15:52:14
Waqar Hussain

Hi all
@ hari : I am totally agree with you, i dont know whats wrong with the other guys, some how they mentioned some of thier logic unclear, If you know smarty its like you can use smarty, what smarty is ? actully nothing else but php, but its usage give lots of advantages like MVC based approach, real time caching, easy to reuse, easy to debug and much more..., anyway I will never avoid Smarty in my professional career.

wish you good luck.

Posted on 2008-08-02 06:14:43

This is an absolutely ridiculous argument for larger projects because with templating systems you can avoid a lot of code duplication by keeping PHP separate from the HTML files.

It's obvious you've never worked on any PHP application which involves considerably more thought process than "Hello World".

Even if you avoid "Smarty" or templating systems in general, you would still find yourself writing a simple templating library yourself to keep having to repeat code segments in PHP. And trust me, large chunks of PHP code in HTML can be as confusing as hell after a while.

Posted on 2008-03-21 20:02:43

Well, the main reason to use Smarty (as was stated many times above) - to separate application logic from presentation logic.
Yeah, right, you can write:
<?php if ($name == 'Fred'} { ?>
Welcome Sir.
<?php } elseif ($name == 'Wilma') { ?>
Welcome Ma'am.
<?php }else { ?>
Welcome, whatever you are.
<?php }?>
But ussually there is a whole bunch of pure php code above that.
As alternative you offer MVC frameworks. Well, are they better than template engines? Maybe, or maybe not. There is the same learning curve and many other problems. So, you can't deny the necesity of logic separation. And that's why Smarty is not bad.

Posted on 2008-03-21 20:02:43

as you have all said, the purpose of templating engines is to separate presentation code from logic.. the problem is, the example above combines logic with presentation.. you can really see how useful smarty can be if you actually follow the rules and use it as it was meant to be used.. for example, in your php code, lets call it example.php:

$name = db->getName(); //whatever...

//NOW we do our logic, which is determining the greeting to use
if ($name == "Wilma") $greeting = "Welcome Ma'am.";
else if ($name == "Fred") $greeting = "Welcome Sir.";
//and then we assign our greeting
$smarty->assign('greeting', $greeting);
//finally we display the template

so in our template file, along with all our html, we just need:


that's it..! much easier for a third-party designer to avoid (and not destroy!)

the smarty syntax is incredibly simple, you can learn to use the basic features in a day.. not to mention it provides many plugins that offer pagination (extremely useful) amonst many other things.. or you can write your own plugins of course..

MVC frameworks are a fine alternative but you can't really beat the simplicity and flexibility of smarty.. i also agree with hari and michael phipps - it is my opinion that any html combined with the php means your website is actually just webshite =)

Posted on 2008-03-21 20:02:43

The argument that "Smarty separates PHP from HTML files" is extremely absurd and ridiculous. What Smarty does is REPLACE the PHP in HTML files with it's own syntax which mimics PHP's, so the problem remains. Same crap, different smell. So instead of designers learning PHP, they have to learn Smarty which is only marginally simpler (notice: SIMPLER and NOT EASIER).

Separation of application logic from view can be achieved by various OTHER means far better than Smarty, such as MVC implementation or a better, cleaner, faster, templating engine.

And what most people fail to realize is that whatever Smarty does, you can do with PHP exactly the same way.

I invite you to search the web for the Savant templating engine. It's probably the prime example the ideal templating engine. Simple, fast, unobtrusive, and uses PHP native syntax to achieve all that Smarty can do, and more, with less resources.

Posted on 2008-05-01 21:22:23

Yes -- obviously to those who say 'seperating the php & html is not needed', obviously you need to go back to design school, because I would never let you come close to touching one of my projects. (not even smell it).

Smarty is absolutely fantastic at splitting html from php. Sure, smarty has its own language but seriously... if you have troubles understanding smarty syntax, you should not be doing php either, because obviously you are an amateur at php (of the millions running around claiming to be 'good programmers').

Sure, the templates contain a bit of logic (loops, if statements and the like), however this should be kept straight to the idea of only being based off of display.

Smarty has proven to be extremly useful to me over the years as business logic and presentation logic are truly separated. I don't care about the compiled templates and they are 'php again', because those are not what I edit.

so funny.... to many amateur programmers running around... Its the one disadvantage to PHP. PHP is easy to become a novice in, however it takes a lot of time to be an expert in. PHP lets its programmers get away with too much... I mean honestly... not even initializing variables before use. That is basic programming stuff! If you don't do that at the minimum... well... its time to start leaving the amateur zone of PHP and brush up your skills!

Posted on 2008-06-23 04:25:22

Amen Drew! You and unit.zero sound like you're the only ones who know what you're talking about.

Anyone can learn how to make a website in PHP, but that doesn't make that person a programmer, and definitely not an expert on code design principles! Even after getting a 4 year college degree in CS and having experience programming in PHP/MySQL, Java/JSP/Servlets, C#/.NET/MSSQL and even some C++, I feel like I'm just scratching the surface.

So save your comments for impressing people that know nothing about programming so when people want to read intelligent discussion on various topics, we don't have to wade through your crap!

Thanks so much!

Posted on 2008-07-21 21:51:57

I have created extremely large estimation systems, various large shopping carts, job boards, etc. - so I'm no amateur to the PHP development environment, nor the ASP, VB, RealBasic, etc.

Smarty Templates are NOT useful, and in fact get in the way and truly cause many issues amongst both the designers and the developers. They're confusing to just about everyone, completely unnecessary, and are time consuming to say the LEAST!

Drew, you seem extremely proud of your work and from what it sounds like, it's SOOOO good that you don't even want people smelling it more or less actually seeing it (sheesh - gimme a break).

Your comments are ridiculous and actually humorous.

For anyone out there thinking of using Smarty Templates, DON'T - you'll find yourself with loss of time and a tremendous headache.

I wish Drew the best in his amazing programming!!! Can't wait to smell his next project (wonder what that smells like...hint).

Posted on 2009-02-05 18:37:49

To those who use smarty for big projects; good for you. Modifing design is a pain when its repeated/mixed in the logic.

To those who use it for tiny projects; boo. There are more people involved than just the programmers and designers. The system admins have to setup up the engines and the compilers. For what? To make the programmers job easier. It just makes it difficult for the majority to take full advantage of PHP. Ive had to give up on great apps because they had dependence my server doesn't have.

Straight code sometimes just works better. Smarty is NOT always the right answer.

The programmer, designer and the admin relationship remind me of a law. The law of conservation of energy states that the total amount of energy in an isolated system remains constant. To get an app on the web the amount of energy remains constant. You can bet if the designer is using less the programmer and admin are using more.

Smarty is flocked to now but there will be something the next generation flocks to and all our knowledge will depreciate.

Posted on 2009-03-05 02:55:47

I think i agree with what you said about "THOSE TEMPLATING THINGS".. Its just that you have to get involved in some weilrd kinda stuff, all in the name of advancement.

Well, i think its kinda cool, but thats if and only if you get a very good tutorial and or material to use in learning this things.


Posted on 2009-03-05 16:00:21

The Smarty way is truly a good way - if you need it. And most projects do need it, even if they know/realize it or not.

When to use smarty (or other template engines) :
- When designers need access to your templates
- When the programmer needs to be forced into good coding practices - especially separating business logic from presentation logic. This forcing is required on 95% of php-developers.

When you can skip smarty and use only php:
- No designers (by good start realizing you need theese)
- The programmer understands the separation issue well enough to well..eh... SEPARATE! (the remaining 5% of php-developers)

I'm myself one amongst those 5%, but I still use smarty. Partially because of the habit, partially because of the potential that a smarty-schooled designer might find its way into the employee despite of the firms incompetent leadership and partially because in any php-development-firm, there is most likely 1 or more developers not amongst the 5%, and they need to be forced. Theese are usually the high degree advanced programmers, switching from c++ or java to our "ridiculous" little language. Theese are the ones that constantly complain about loose typing, the lack of namespaces, and the need to bother themselves' busy minds with the lowbie presentational layer called html. Theese are the ones that create themselves a function to write a BR. Theese are the ones that think KISS is just a rock band, and spend a ridiculous amount of time trying to fit everything into a service-based system, where they cant rest before the singelton-pattern is in place and where everything is XML (needed or not, smart or not). Theese are the ones using a horrible amount of time programming in their hyper-advanced system just to make a mediocre guestbook (ofc it is very safe now...). Theese are the ones with knowledge of about 2% of the built-in php functions, utilizing substr, strpos, str_replace, if and else to proposterous, idiotic levels. Theese are the ones running your company bankrupt because of efficiency troubles. Theese are the ones putting the blame on php for "letting them" make the mistakes they do. "A real programming language wouldn't allow this programming mistake!" LEARN PHP BEFORE YOU WRITE, TAKE RESPONSABILITY FOR YOUR CODE!

Frustration "out".

Posted on 2009-03-21 13:33:35

Well... Templating sucks.. anyway you can write your own templating engine rather understanding (hardly) someones work

Posted on 2009-04-07 13:41:22
Help with Smarty Code

I do hope you can help me with this. How exactly can you break each word on each title with comma? Is this possible by adding a code?

I know you can break series of titles by adding {cycle values=", , , , ,"}.

What about on a single title but would like to break each word in it with a comma.

Appreciate any response from you either on this post or via email.


Posted on 2009-04-10 20:10:55

Well i used smarty 2 years but finally back to php templates itself. Smarty was pleasant and easy to work with but i come to the conclusion that it's only adding another unnecessary layer.

I think Smarty is great for someone who doesn't have MVC programming habbit but want to seperate business logic from template. But when you are able to write websites with MVC pattern or with the help of a framework, Smarty will not be the best solution.

A simple registry class can help you to achieve good code separation for small / medium website. Ex:

class registry
private $vars = array();

public function __set($name,$value = null)
$this->vars[$name] = $value;

public function __get($name)
if(isset($this->vars[$name])) return $this->vars[$name];
else return null;

$tpl = new registry();

//do logic stuff...

//assign tpl vars

$tpl->pageTitle = 'my page title blabla';
$tpl->datas = array('x','y','z');


<h1> <?php echo $tpl->pageTitle; ?> <h1>

<?php foreach($tpl->datas as $data) { echo $data.'<br />'; } ?>


Posted on 2009-05-17 22:14:35

I've been using SMARTY for years and I must say that it makes web development much easier (and cleaner). I do agree that the templating language is a bit looser than it should be. But isn't php itself guilty of that as well? But if you stick to the SMARTY basics (variables, loops, conditionals, includes) it's really smooth. It reminds me a lot of Perl's HTML::TEMPLATE.

I've also used the templating solution that CAKEPHP adopts and I've found that it provides too much abstraction. And still, it litters your template with PHP tags. Simple operations are often difficult and the learning curve is much higher than that of using SMARTY.

SMARTY is also great to use when working with JQuery or even creating XML files. If used correctly, SMARTY is successful in truly separating business logic from display logic. I'm actually a bit surprised by the comments here. Hey, but whatever works for you...

Posted on 2009-05-29 20:49:50

what these smarty idiots do not realize is, that you can seperate logic from design with php.

i use templates, and my template language is what? yes, php. and i only use php in templates to present dynamic content.

i have never seen such a useless, harming software and it scares me, that people are so stupid to use it.

Posted on 2009-06-19 19:06:27

I am heppy to find this blog.

I am a new(ish) PHP developer and have been experimenting for a while with emgines like Smarty and i honestly failed to see the point in them.

The only good reason to learn it is in case you come across an application that has been entirely written in smarty.

In my mind, it is no different than creating a template with empty modules and simply writing files in html/php that can be plugged anywhere into the template eg

Header Header Header
code1 code2 code3
Footer Footer Footer

So all 3 pages are the same except the code that is surrounded by the template header and footer.

It could take even a PHP expert a while to figure out what on earth smarty is doing and why it is doing it that way.

For example, smarty that i have seen uses tables to position elements on a web page. That is something i did on my first website and now its a pain to maintain. Floating divs to me work much better.

Posted on 2009-10-14 17:18:17

I used Smarty for years. It has a huge benefit - a real html separation. Don't confuse MVC frameworks with Smarty - they are totally different products and server different purposes. And most MVC frameworks won't give you the real front-end separation, you still have html files full of <?php tags. It's messy, unorganized and on any medium to big scale project becomes unmanageable.

Posted on 2010-03-18 23:39:23

Andrew wrote
"For example, smarty that i have seen uses tables to position elements on a web page. That is something i did on my first website and now its a pain to maintain. Floating divs to me work much better."
you CAN write your own HTML to use whatever you want to layout a page: tables, divs, elephants....Smarty is not Dreamweaver.

Posted on 2010-03-18 23:40:51

I've viewed some smarty code in a php book and have realised that it is useless except the MVC aproach. It makes the code run slower becuse the code is parsed twice. You can use many MVC frameworks to seperate logic and view parts of the code. I've developed my own php5 mvc framework and besides model view controller system it has many features like seo urls,cache,helpers,plugins,modules(under development) etc. and is enough fast for web applications. I develop it when i need new features, extensions or corrections. It is flexible and may be used for any type of web applications.

In fact there is no need to learn another language for template coding. It can be done easily by using native php code and using the alternative syntax of php without using {} blocks. In fact PHP (old abbr. Personal Home Page) was firstly developed as a template system. Today Facebook uses a system that compiles php code after translating it to C++ code to gain high performance for serving faster. Most of the actions facebook does are ran by native compiled programs instead of php. The real advantage of php is its portability. You dont need to compile source code for every different server platform. Thats why php environment is compiled for every different server platform.

I think using a template language like smarty is bad for performance and for having to learn a new template language.

Posted on 2010-04-03 13:59:43

OK first of all i already agree with this thread and that template engines such as smarty that basically change the php tags to { and }

I am an experienced PHP programmer who is currently developing a open source framework

The way i have built my template engine is is i have to main classes!

the first class is the View (MVC) and this acts as a registry with assign and output methods

within the controller the user will use $this->View->Assign('key',$variable);

and when they use the Output method passing in the template file the View class sends both tpl name and vars to the ViewLoader class witch in turn includes the template using output buffers to capture the compiled code! this is all done within the constructor

now because the main tpl file is included within the constructor the actual template file has access to its methods witch in turn inlcude url() escape() inc()

these functions are helpers within the templates.

This has all the effects of smarty or other template engines and its only parsed once

if you was to compare bench marks of 1000 compiles of smarty compared to general php language im sure you would switch straight away from your template engines!

All smarty does is convert {$var} into <?php echo $var; ?> and stores it as a cached file.

Go take a look at your cached files! its just going back to normal php!

in turn uses resources beyond belief !

dont be idle guys, use the syntax provided by php witch is way more stable and powerfull then ANY template engine!

Thanks for your discussion Code Assembly!

Regards Robert! (LitePHP)

Posted on 2010-04-18 02:40:31

This here is my template system so people who assume that MVC Frameworks cant have the functionality of smarty or incorrect as ive proven here!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">
<?php $this->include_file('/sections/global/head',array('page_title' => 'Home'));?>
<div id="wrapper">
<?php $this->include_file('/sections/global/header_top'); ?>
<div id="container" class="clearfix">
<div id="left_container">
<?php $this->include_file('/sections/main/welcome'); ?>
<div id="right_sidebar">
<?php $this->include_file('/sections/sidebar/downloads')?>
<?php $this->include_file('/sections/sidebar/news')?>
<div class="clear"></div>
<?php $this->include_file('/sections/global/footer')?>

Posted on 2010-04-18 02:53:08

Wow, I've never seen a thread with so many coders talking out of their hats! I don't use Smarty but I have been programming in server and client side languages and designing the IA, graphical UIs, and layouts of web sites for over ten years...

Smarty is intended for the designer, not the coder. Investigating Smarty and I would say that they aren't doing the best job at this. However, the purpose of it is entirely different than that of a framework like Zend.

This discussion has devolved into why Smarty is bad if you're a PHP coder...not one person mentioned why it might be good if you're NOT a PHP developer and instead are a page designer.

Personally I wouldn't let a coder near my page/template design unless they also exhibited competence in design concepts, something very few have. Just like you shouldn't expect a designer to learn and implement best programming practices -- it's not what they specialize in, right.


Posted on 2010-08-20 21:40:44
Andrew Hughes-Games

I don't think you understand how smarty is meant to be used.
You are trying to implement logic in your templates, this is how you should do it.
$sex = 'male';
if($sex = 'male'){
$message = 'Hello sir';
}elseif($sex = 'female'){
$message = 'Hello madam';
$message = 'Are you transgender?'

In your template

This way you have all you logic in your php file and it is not cluttered with logic and php code.
You then put a simple {$message} tag in your html code to display the message. Maybe you should learn how to actually use smarty before you make judgements?

Posted on 2010-12-16 04:36:43

Smarty is only used for separation of Design and Logic...Blah
Smarty is just different syntax, but it does the same thing as embedding php, only less robust and more overhead.

You could separate Design from Business logic by using one of the many PHP MVC Frameworks out there..And guess what?..I don't see any of them using Smarty in any of their Templating Engines.

So those who say that you cannot write highly scalable applications without using Smarty..I say to you: Keep up with the Times..Check out Zend Framework.

Posted on 2011-01-08 19:55:44

PHP evolved his coding features, but didn't evolved the presentation features. So at least for now template engine is the solution, because template engine makes a website easier to maintain/update & creates a better development environment by enabling developers & designers to work together easier, also modern template engines load precompiled php templates, for performance same of php files.

I advice to take a look to this benchmark

try at least to smarty, rain, dwoo and savant.
I'm positive you'll find one to use in your project and you'll improve your production!

Posted on 2011-01-13 19:41:44

Okay, this is simple.

If you're using MVC, and/or work with designers, then template engines are great. That's only if you are using it right.

If you are putting logic (code) your templates, you are doing it wrong. Use PHP for logic, Smarty for the template, assign the output of your logic to a token, and assign that token to template. A designer can work around that. You don't have to "print / echo" html.

If you cannot use it right, then by all means, don't use Smarty or any templating language. I would suggest not programming, either. Templating engines are nice. Has anyone worked on a perl site, and had print HTML without Mason? Not pretty. Even Ruby on Rails uses templates.

Use the right tool for the job. If you are printing "HTML" in the same page that you are performing your logic (queries, loops, etc), then you are doing it wrong. If you have a few lines, that's fine, but if you are printing it all... Not only did you fail in your web design, you have also failed in your project design.

Do whatever works, but don't do it wrong.

Posted on 2011-02-01 21:29:08

hi, ya all.. seems alot of people hate smarty already.. but seriously smarty is a next generation thing. believe me it is. y? the whole idea is to divide and conquer.. personally i don't like html file to be in php extension... and it make error detection easy.. alot easy. . we have a framework here that is using smarty
as its template engine. and believe me its a pure blessing.. we just have to assign and fetch.. beautiful isn't it.
best of luck ya all.

Posted on 2011-03-10 13:33:44
webmaster Grumpy

i agree with the author. I have written my own template engine, why. No overload, and fits my need. My template tags look like <#content#> <#db_names_all#> etc. Easy to read and easy to work with for designers.

Posted on 2011-07-27 15:31:50

You are entirely right. Things are getting much worse when you have to develop Smarty code written by somebody in a ugly and chaotic way. I'd like to say, that in my opinion Smarty templates system is just designed for such a style and supports ugly coding.

Posted on 2012-02-09 13:49:03

Yes, smarty can do a lot what PHP can do, so in some sense smarty replaces PHP as the template "language".

On the other hand you don't have to use all those features, and in fact the less you use them the better you have succeeded to make your app readable to others.

The beauty of templating engines such as Smarty is that after the coder has done his thing, he can leave to do other things. But the app can still continue to evolve, change appearance etc. as the webdesigner already has everything he needs to have: the data what needs to be displayed.

And that is the key. Web page does not need to know where or how the data comes from, if it's a database or CSV text file. It does not need to know the logic how it's put together.

The same way the programmer doesn't need to know how the data is displayed. Or at least I would not like to look at my old code 2 years later when the table structure changes axises, or whatever, somewhere in the middle of my phphtmlphp page. The same way the webrogrammer don't want to touch his pages when we do a db upgrade.

So the writer of this article doesn't really understand how templating engine should be used.

Posted on 2012-02-17 14:21:52

I fully agree with Nrde: albeit not necessary, using Smarty will FORCE you to write cleaner and cleverer code. Using PHP-only makes it too easy to mix HTML and code, leading to apps where it's nearly-impossible to change the design : as a team leader I've too often seen this!

Posted on 2012-04-18 11:00:40

I'm a little surprised at this. PHP sucks, and Smarty is overengineered, but the reason for using a template system has nothing to do with either of these points. It's all about security. Writing the "template" code in PHP is just ASKING for injections and exploits, and securing that against attacks means reinventing all of the special handling that any given template system has already implemented -- and probably getting it wrong.

Furthermore, a good template system helps insulate the developer from the inconsistencies of PHP deployment. Unless you're writing code that will ever only run on one server, you can't rely on any given server configuration, because any given server could change any setting in php.ini for any reason.

The fact that the article is recommending changing the server configuration is a sign that the author is naive and doesn't understand security. A blacklist is NEVER the right solution. A whitelist often is, and a template system is in essence a whitelist of permitted functions that a template is allowed to use.

Posted on 2012-04-28 18:38:13


The criticism reminds me of the one when the ethanol-petrol was introduced and the rumours spread claiming it to cause all sorts of problems from broken gearboxes to frozen door locks and gay behaviour :)

"Smarty supports bad coding" is one of the most unbelievable arguments I have ever seen. Pure PHP does not eh?

Posted on 2012-06-12 13:41:35

Separating presentation from business logic is a great idea, especially when working on big projects.

MVC means no need for Smarty. I'll repeat just so people can get that concept.


Now I'm not a smarty hater and in existing systems smarty and other template systems have done a good job, they have helped designers etc.

MVC avoids the necessity for smarty as the Views (the V in MVC) splits presentation from business logic, meaning the presentation file(s) don't need to get parsed twice and the only difference in how the View file appears compared to the Smarty template file is minimal.

So you get the original benefit that Smarty templates provide plus a performance boost!

Posted on 2012-07-11 01:26:21

Awful, awful argument.

I love people throwing a wave of the hands to "use a MVC framework", ignoring the fact that in your MVC framework, you'll have... ta-da... a template engine.

To the absolutely clueless advocating rolling your own: Stop. Stop coding. Stop telling other people how to code. You have no idea what you're talking about. Smarty will be better than what you come up with. Use it.

Can I ask that everyone who posted in favour of this rant add their LinkedIn profiles, so I can add you to my list of "clueless devs - do not hire ever".


Posted on 2012-07-10 14:31:21

And Andrew Hughes-Games "criticism" is equally bad. That's _NOT_ how you use a template engine, and you've just splooged presentation all through your business logic.

Posted on 2012-07-10 14:41:03

Tomandyourmom you claim that we don't know what we're talking about yet your answer seems that firstly know little at all about MVC frameworks, secondly you assume that they all use template engines and finally you seem unwilling to open your eyes to the fact that there are more practical and efficient solutions than Smarty.

Hasin Hayder who wrote the book 'Smarty [ISBN 190481140X]' wrote an article on his personal blog entitled 'Once upon a time there was Smarty!' which explains why there is no need to use Smarty anymore.

BTW why don't you check out his LinkedIn profile?

Posted on 2012-07-11 21:20:47

haha that made me laugh I take it you think all MVC frameworks use a template engine?

Posted on 2012-07-11 18:58:26

WMJ - you do know that MVC is a technique, not a specific framework, right?

And that Smarty is 100% able to fulfil the "V" part of a MVC framework, right?

And that Smarty gives a _big_ performance increase, much bigger than the "usual suspects" of full PHP frameworks, right?

Because if you don't know those things, you might look like someone that has no idea what they're talking about.

Posted on 2012-07-11 11:49:28

"A _big_ performance increase", that made me laugh a lot.

If Smarty increased the performance of your projects this much, please give me your LinkedIn profile so I'm sure to never work with you, what is the name of your company ?

PS: you were the once talking about MVC Framework, he just answered you so don't try to give him lesson
And saying Smarty is able to fulfill the V part of MVC is just stupid and wrong, it's the way you use it that determine what it can fulfill. PHP can handle the MVC part of MVC you know it, right ?

I hate those people so proud of them without argument.

Posted on 2012-11-07 10:59:56

I agree, smarty is pointless. I have had to work on smarty projects and I hated it. Very annoying having to basically learn a whole new syntax to do the same job which can be accomplished any number of ways. I just find it over engineered.

To the guy who said 'It's obvious you've never worked on any PHP application which involves considerably more thought process than "Hello World".' all i can say is what an idiot.

Posted on 2012-11-12 18:37:50
Jose Maria Rodriguez

Please, take a look at this template engine (Siviglia Templating): http://code.google.com/p/siviglia-templates/
It doesnt require any special syntax to loop, branch, use variables...As you can use PHP for all that.It's only "special" syntax is used to specify what subtemplates are needed to render the current one.
Because one of its goals is not to have to learn a whole new language (like smarty and clones), when you already have PHP.

Posted on 2013-01-01 18:14:55
Steve Conley

People tend to forget Smarty is, one might say, legacy PHP. Back in PHP3 / PHP4, we really didn't have many options insofar as MVC is concerned. Smarty was introduced as kind of a hacky way to cobble together a performant MVC.

With PHP5, the doors to actual OO builds were opened. People still clung to smarty for some reason ... maybe the same reason people cling to Windows XP :) It's what they know; I read the other comments and people swear up and down that Smarty's the way to do MVC, and that clearly folks that don't like Smarty are doing it wrong. I suspect many of those folks are people who have been doing PHP a really long time, or folks who started out working on code built by those folks.

There's really no point to it, now. It's just clunky; it requires more webserver writable directories for its template files, it requires learning a new "mini language" to use it. It confuses designers more than it helps, because most of the new blood in the design world know some PHP but have no idea what this smarty junk is.

Business logic should never be in your templates, but there's a lot of much better, much more direct ways to handle that. Smarty served it's purpose back in the day, but it's time to put it to pasture. :)

Posted on 2013-01-23 17:56:34

I will keep this short but i just wanted to pitch in a little.

Ive found that using php/html its really easy to keep the logic side nice and clean.

When it comes to the "template" side with all your html lay out at somepoint you need to use php to get the data you need into the page, So yes, keep the logic side clean and free of html. but the html side of it will at least require minimal php code to print something worthwhile from your logic side.

RE: smarty, i find it a pain to work with and i prefer not to when i can help it, sadly its not always possible

Posted on 2013-03-17 00:52:07

Make yourself heard



All Posts

All Comments

© Copyright CodeAssembly

All code is licensed under LGPL, unless otherwise noted