Why not use Smarty or another template engine? (http://smarty.php.net/)
Smarty has a lot of overhead. PHP is a perfectly good templating engine all by itself.
What the OP may or may not have understood is that PHP and HTML can be mixed together:
--- <html> <body> <div id='content'> <?=$content?> </div> </body> </html> ---
As for Smarty, well, anything it can do, PHP can do better and faster, without the overhead :)
--- <table> {section name=mysec loop=$name} {strip} <tr> <td>{$name[mysec]}</td> </tr> {/strip} {/section} </table> ---
Could just as easily be:
--- <table> <? foreach($names as $n) { ?> <tr> <td><?=$n?></td> </tr> <? } ?> </table> ---
Alternating table row colours? I just slapped this together in about 1 minute -- I'm sure with a little more work (or a class), I could keep it all out of the global name space too!
--- <? function alternator($val1,$val2,$name='alternator') { // initialise or increment the global counter // called ${$name}_counter if(!isset($GLOBALS["{$name}_counter"])) { $GLOBALS["{$name}_counter"] = 1; } else { $GLOBALS["{$name}_counter"]++; }
// set ${name} in the global space to either // $val1 or $val2, depending on the odd/even // state of the counter if(is_int($GLOBALS["{$name}_counter"] / 2)) { $GLOBALS[$name] = $val1; } else { $GLOBALS[$name] = $val2; } } $names = array('Fred','Jane','Bob','Kate','Hank','Nicole'); ?>
<table> <? foreach($names as $n) : ?> <? alternator('#ccc','#eee',"bgcolor") ?> <tr bgcolor='<?=$bgcolor?>'> <td><?=$n?></td> </tr> <? endforeach; ?> </table>
And when you hit a wall in Smarty, you can't do much other than request a new feature... in PHP, just code it! You also don't have to learn YET ANOTHER syntax/language, you don't have to compile templates
Smarty's forte (and it's downfall) is that it limits what you can do. On one hand, you're not letting untrusted on unskilled template designers loose with the full features of PHP, but on the other hand, when a skilled template designer with PHP experience hits a "limitation" as to what Smarty is capable of, they're stuck... whereas PHP-based templates are only limited by the skills of the programmer and PHP itself.
If your "template designer" is in fact a reasonably skilled and trusted PHP programmer, then Smarty is *overkill* and *very limiting*. If your "template designer" only knows HTML, then perhaps the full power of PHP is a little unsafe -- which is where Smarty wins.
Eeek -- sorry for the long post and for straying off topic, but I think Smarty is used in situation where PHP and some well-built functions will do just fine.
--- Justin French http://indent.com.au
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php