NYCPHP Meetup

NYPHP.org

[nycphp-talk] Smarty Templates

csnyder chsnyder at gmail.com
Wed Nov 2 13:03:50 EST 2005


On 11/2/05, Mark Lassoff <mark at wildwoodinc.com> wrote:
> I hope I'm not starting a religious war here, but, I'd like to get some
> opinions on Smarty-Templates.
>
> The sepearation of code logic and display seems intriging to me, however,
> I'm not sure that programmers could be able to create the back end logic and
> walk away, leaving the front end totally to the designer.  The front end
> smarty-templates code could get complex-- Having a information from a
> multi-dimensional array displayed occurs to me.
>
> Any experiences you might have would be appreciated.
>
> Mark Lassoff
> Web Developer
> Wildwood Inc.
>


Templates are essential, and Smarty is fun. But there is a lot of
overhead to Smarty, you have to learn the ins and outs of another
language, and you end up with a more complicated system (more moving
parts, more opportunities for things to go wrong).

In a NYPHP presentation a couple years ago (has it been that long?) we
put Smarty head to head with a couple other template languages, and
with PHP itself. PHP blew them all away in performance and (in my
opinion) simplicity.

PHP makes an excellent template language when used with "short tags".
Dreamweaver still can't handle loops and conditionals, but it doesn't
choke on the code either.

An example of PHP template:

<html>
<head>
<title><?=htmlentities($title)?></title>
</head>
<body>
<p>Today is <?=date('M j, Y')?>.</p>
<ul>
<?foreach( $messages AS $message ){?>
  <li><?=htmlentities($message->subject)?><br />
       <?=htmlentities($message->body)?>
  </li>
<?}?>
</body>
</html>

When working this way you need to write a simple template class that
will search for the appropriate template to use from some path. Once
identify the template to use, you just include() it (possibly inside
an output buffer) and you're done.

--
Chris Snyder
http://chxo.com/


More information about the talk mailing list