[nycphp-talk] Smarty Templates
John Daly
jdaly at panix.com
Wed Nov 2 13:59:12 EST 2005
The Smarty I used was just a simple templating language. The structures
were set in a PHP control file and assigned to template variables. Big
decisions like 'auth' 'logged' etc would be PHP decisions of what template
was called, and the standard logic of {if results then loop else nada}
would be the kind of Smarty code that I would put in the template. I think
of it as output logic and an acceptable bare minimum. The whole thing for
me was the designer would rather eat Brussel Sprouts all day than work with
it. That's a very big problem.
I swear by templating, even it the team size is only one -- it forces a
presentation/business/date layer thought process. I use Smarty and have
a love/hate relationship with it. It has many powerful features, but as
some have noted, forces you to learn YAL -- yet another language. And at
times, understanding the "flow" of things can be tiresome.
At the Zend conference, I heard that Flicker uses Smarty, which in
essence nullifies my performance concerns. And it has a built-in caching
mechanism.
I am intrigued by Chris' comments and analysis though. If used as
intended -- for design, a Smarty .tpl should have an absolute minimum of
logic (just simple presentation logic) and mainly HTML with tags. So if
you can force yourself to use a PHP template structure of
<?=htmlentities($stuff)?>, why not? But how will you eliminate "PHP
creep".
Cliff Hirsch
-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of csnyder
Sent: Wednesday, November 02, 2005 1:04 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] Smarty Templates
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/ _______________________________________________
New York PHP Talk Mailing List
AMP Technology
Supporting Apache, MySQL and PHP
http://lists.nyphp.org/mailman/listinfo/talk
http://www.nyphp.org
_______________________________________________
New York PHP Talk Mailing List
AMP Technology
Supporting Apache, MySQL and PHP
http://lists.nyphp.org/mailman/listinfo/talk
http://www.nyphp.org
More information about the talk
mailing list