There’s a debate going on here regarding Smarty‘s usefulness as a developer tool. It was sparked (again) by the launch (or at least newly noticed) nosmarty.net. I commented:
I don’t understand how ZF or Symfony or any framework can be an “alternative” for Smarty. Smarty is not a framework — it is simply a templating engine. It should not be used as anything other than a component of the view layer of your MVC application. Just like any other software, it has a learning curve and a certain amount of quirks. Using Smarty does not guarantee good design — that still needs to be handled by programmers who have more experience than writing a “Hello, World!” program and reading a tutorial.
I think the fact that it’s been around since 2001 and is still in use is a testament to it’s usefulness within the community. If Smarty is used in the right manner, I don’t see why it can’t have it’s place within the arsenal of tools for developers to use.
It was countered by Paul M. Jones with:
In my opinion (note the small “o”) there *is* no right manner in which to use Smarty. It is the solution to a mis-stated problem.
I suppose I shall have to expound on that at greater length in another blog post.Oh, I already have! http://paul-m-jones.com/?p=273
I understand this point, however I still have one reason to use Smarty: PHP is an ugly templating language. I’ve used Smarty and Symfony (which relies on PHP’s alternative syntax for templating) and I still prefer Smarty.
The examples on nosmarty.net generally site one instance of echoing a variable. In this small case, sure, I can see — why use a heavier templating system that takes longer to parse and can be a bitch to configure and deal with. However, if you’re looking at a portion of a html page that has to output multiple variables, Smarty is much easier on the eyes.
SMARTY:
<td>Name</td><td>{$name}</td>
<td>Email</td><td>{$email}</td>
<td>Phone</td><td>{$phone}</td>PHP:
<td>Name</td><td><?php echo $name; ?></td>
<td>Email</td><td><?php echo $email; ?></td>
<td>Phone</td><td><?php echo $phone; ?></td>
When you start repeating <?php … ?> everywhere it gets fairly redundant, and, frankly, ugly.
Perhaps my use case for Smarty is a bit selfish, but, ultimately, programming style and comfort boils down to personal preference. Most, if not all, programming tools have the ability to be misused. I still consider Smarty to be a useful tool in my development arsenal. Though I have not used smarty in over 2 years now, using strictly PHP templating (mainly due to Symfony’s templating conventions), I would happily start using it again to regain readable templates.
Recent Comments