Re: Why Smarty?
| From: | Matthew Weier O'Phinney | Date: | Fri, 25 Mar 2005 18:06:46 +0000 |
| Subject: | Re: Why Smarty? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12371@lists.php.net to get a copy of this message | ||
* alp güneysel <x@alpalp.com>:
> I know it sounds like a dumb question, but let me say this first. I use
> smarty, with HTML:QuickForm, Pear:DB and Pear:Auth and when i'm developing a
> php website, i always use this combination, which saves me great time.
>
> But I got a mail from my boss on a server we're developing:
>
> ========cut========
> I browsed the web a bit as I was writing this list up and have more notes,
> but for now I want to focus on the one question:
> "What template system?"
>
> I found the following articles very compelling that staying closer to PHP
> and avoiding a heavy template engine.
>
> http://www.phppatterns.com/index.php/article/articleview/4/1/1/
> http://www.massassi.com/php/articles/template_engines/
> http://phpsavant.com/yawiki/ (describes savant template
> approach)
> http://phphtmllib.newsblob.com/ (another lighter weight
> template
> system)
>
> To Alp:
> So, Alp, I'm pretty disposed to agree with the reasoning expressed in the
> above articles. Finding these links helped me articulate my feeling. Is
> there something I am missing about Smarty you would like to add or
> demonstrate?
> ========cut========
>
> He is basically reluctant to see new things added which is not in his
> control.
>
> So, do you know any articles about why one should use smarty and why it
> makes php development far easier, and why a homegrown template solution is
> not very approciate for an enterprise scale server system?
First off, I'd question the article from the phpsavant.com site; the
author of that is basically promoting his own template system (Savant).
Granted, Savant is closer to PHP than Smarty, but I'll get into that
later.
There are several comments I could make. First, I'm not a Smarty zealot.
I use it, and it's my current templating system of choice. But I also
can see the arguments made in the articles listed as valid.
Things to consider:
* Will all those working with the templates be familiar with PHP?
* Does Smarty actually cause overhead in your system?
* Smarty compiles templates into PHP code ONLY when the template
changes, so after the first time a template has been processed,
you're running PHP code after that -- unless your templates change
on a regular basis.
* Would equivalent PHP code necessarily run faster?
* Would you lose flexibility if you don't use templates?
* Would switching to straight PHP or a more PHP-like templating system
(Savant, handgrown system) cause more work for you or others?
Where I work, we have a number of people editing templates. Not all of
them are familiar with PHP. We can set them loose on the templates and
feel pretty confident that things will continue to work -- and, if they
don't, we can catch such issues on our development server. I personally
don't buy the argument that PHP is so simple to learn that anybody can
-- many people I know working in HTML can't even grasp HTML fully. Thus,
I cannot buy the argument that working closer to PHP is a good answer
when working with a diverse team of people.
I've heard Smarty take some flak for compiling its templates. The
arguments are generally along the lines of, "Why write a meta language
that has to be interpreted into a language that is itself interpreted?"
But, as I note above, this interpretation only happens with NEW or
CHANGED templates; once compiled, Smarty is simply running PHP code.
This gives the flexibility of a meta language that does a subset of what
PHP does, as well as the speed benefits of executing just PHP code.
Additionally, you lose flexibility if you go to PHP only for generating
pages. Templating is an absolute must if you wish to maintain
flexibility of design. There's a reason that MVC is such a popular
paradigm in web design -- and one of those reasons is that sites OFTEN
need makeovers, and templates allow this with minimal fuss.
Finally, if *you* are familiar and comfortable with Smarty, switching to
another system is going to increase your development time at this point,
as you'll need to learn new skills. The only reason to do this is if the
benefits of switching outweigh the costs of switching. This, only you
and your boss can judge.
If you need benchmarks, you should compare PHP only code (i.e., PHP
generating HTML) with code using Smarty with *compiled* templates. You
may also want to develop a benchmark of a Savant template, again,
against the same app using Smarty with *compiled* templates.
Good luck!
--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:matthew@garden.org | http://vermontbotanical.org