Apr 8 at 10:26am, Justin French wrote:
PHP itself is a great templating language :) <h1><?=$title?></h1> <table> <? foreach($staff as $person): ?><tr> <td><?=$person['firstname']?> <?=$person['surname']?></td> <td><?=$person['role']?></td> <td><?=$person['phone']?></td> <td><a href='mailto:<?=$person['email']?>'><?=$person['email']?></td> </tr><? endforeach; ?></table>
Uhhh, yeah--that's not a templating, that's called spaghetti code :)
+1 - Use of buzzword
You get the concept. Smarty, as you know, basically takes a Smarty template and writes PHP code similar to what you've done above, then writes out the .php file, and includes it when you render your template. So you'd get nearly the same effect by writing the PHP as a separate file and including it as your last step, and it acts as your display logic.
That may be acceptable to you, as a PHP programmer. If you're the only one who ever needs to modify your templates then that's great, more power to you. I'm sure that you would have no problem having many levels of nesting all over the place and not screwing anything up. So be it. But that's you.
I guarantee another person not as adept at PHP will screw that code up, and there is less potential for that with a Smarty template. If you know PHP as well as yourself, it should be plain to see how Smarty is just a wrapper over PHP that makes templates easier to build and maintain. For a designer or non-coder, Smarty will be easier to learn than PHP.
You must work with some real idiots. You can teach them to write {$variable} but you can't teach them to write <?=$variable?> ?? Give your people some credit. If they can learn {section name="foo" loop=2 show=TRUE}{/section}, then they can learn for($x=0;$x<2;$x++){ }, can't they??
However, there are practical limitations on what you can easily accomplish with this approach, and Smarty addresses those issues. And you're worse off if you invest a lot into building your sites this way, and then realize you need some better templating strategies later.
I'm sorry, but if Smarty takes your "template" and turns it into code like the example above, EXACTLY what "limitations" are you going to run into using the method above that Smarty solves?
You can still separate your logic from your presentation, template designers can still use quick, simple "tags" to include code, and the upside is that people familiar with PHP don't need to learn ANOTHER language (that's what Smarty is) -- they can dive straight in.
You can consider it it's own language, but really it's more like PHP with different formatting. Which is why it's different than what you're doing above--it's designed to facilitate templating. Your method is just poking in variables and PHP into inline'd HTML. It works, but you're missing some of the power of Smarty if you think that's all it's good for.
Fight it all you want, but PHP is a templating engine, too. That was it's original purpose. And again, what "power" of Smarty are we missing if Smarty just turns the template back into PHP code, anyhow?
The question is, do you want to give your templater designers full access to the power of PHP, or not.
In other words: are your template designers already good PHP programmers? It's not just hype, it solves real problems, even if you don't have them.
You can either teach your designers the Smarty language or you can teach them PHP. Which one will set them up for success?
Now, all that being said, I am a fan of Smarty and use it in some applications. But, there's no reason you can't use straight PHP and achieve the same results by simply separating presentation logic from your code.
-- ---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php