<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated on Thu, 20 Nov 2008 21:46:10 -0600 -->
<rss version="2.0">
  <channel>    <title>Codeassembly - Why template systems like smarty are useless and sometimes bad</title>
    <link>http://www.codeassembly.com/feed/comments/20</link>
    <description>CodeAssembly - Simplicity is prerequisite for reliability - Comments</description>
    <language>en-us</language>
    <managingEditor>contact@codeassembly.com</managingEditor>
    <webMaster>contact@codeassembly.com</webMaster>
    <generator>RSS Feed Generator</generator>
    <item>
      <title>Waqar Hussain</title>
      <description>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.</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#148</link>
      <pubDate>2008-08-01 23:14:43</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#148</guid>
    </item>
    <item>
      <title>Mike</title>
      <description>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!</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#142</link>
      <pubDate>2008-07-21 14:51:57</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#142</guid>
    </item>
    <item>
      <title>Drew</title>
      <description>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!</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#132</link>
      <pubDate>2008-06-22 21:25:22</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#132</guid>
    </item>
    <item>
      <title>Aeglos</title>
      <description>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.</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#103</link>
      <pubDate>2008-05-01 14:22:23</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#103</guid>
    </item>
    <item>
      <title>unit.zero</title>
      <description>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
$smarty->display('example.tpl');

so in our template file, along with all our html, we just need:

{$greeting}

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 =)</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#79</link>
      <pubDate>2008-03-21 14:02:43</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#79</guid>
    </item>
    <item>
      <title>evll</title>
      <description>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.</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#61</link>
      <pubDate>2008-03-21 14:02:43</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#61</guid>
    </item>
    <item>
      <title>hari</title>
      <description>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.</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#58</link>
      <pubDate>2008-03-21 14:02:43</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#58</guid>
    </item>
    <item>
      <title>ion gion</title>
      <description>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 )

if:
//block
endif;

foreach($items as $k=>$v):
//block
endforeach;

and the list goes on(for/switch/do/while ...)

PHP itself is a fully fledged template language.
</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#6</link>
      <pubDate>2007-11-19 08:52:14</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#6</guid>
    </item>
    <item>
      <title>CodeAssembly</title>
      <description>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.</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#5</link>
      <pubDate>2007-09-30 15:01:48</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#5</guid>
    </item>
    <item>
      <title>Michael Phipps</title>
      <description>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?</description>
      <link>http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#2</link>
      <pubDate>2007-11-19 08:51:27</pubDate>
      <guid isPermaLink="true">http://codeassembly.com/Why-template-systems-like-smarty-are-useless-and-sometimes-bad/#2</guid>
    </item>
  </channel></rss>