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 :) 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. Unless your needs never exceed the very basics like you have demonstrated above, you'll be hosed when another person needs to modify your template. Which goes back to a templating truism never in dispute: if this is all you want templating for, it's six of one, half a dozen of the other. 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. > 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. > 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. --Kelly -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php