[UPHPU] Template systems
Jacob Wright
jacwright at gmail.com
Thu May 3 12:13:17 MDT 2007
>
> Jared Stevens wrote:
> > Hey all -
> > I'm sure this has been discussed before, but I want to freshen the
> > debate. I've used Smarty for a while, but I've often wondered if there
> > is anything better out there in the world of PHP. I've briefly used a
> > library called Phastplate, but it seems like development isn't going
> > anymore on that. I can't find the homepage for it on the web either.
> >
> > The main thing I like about Smarty is its ability to do formating and
> > stuff on the fly, as well as the way it can handle arrays. Once I got
> > the scripting language down, it was really convenient. I also like how
> > you can use QuickForm together with Smarty and format forms and stuff.
> >
> I like both Smarty and plain PHP. When working with a team of
> less-experienced coders, Smarty is often much better because it forces
> MVC. I hate having to teach less-experienced coders that it is bad
> practice to be doing data processing and defining functions in a php
> template file.
>
> I also like the namespacing of Smarty; that is anything inside the
> template won't conflict with other global php variables. I liked it so
> much, in fact, that I wrote a QuickTemplater class that uses extract()
> to do the same thing for plain php templates. (see
> http://pastie.caboo.se/58630).
Hey! I did the same thing. :) But then I kept going with it and built my own
templating system. I agree with the others about the less-effectiveness of
learning templating syntax when you can do the same thing with PHP. The
template system I built adds some additional benefits for designers and adds
in page caching (two benefits not derived by default from PHP). It uses
attributes in the HTML as the dynamic markup thus allowing dummy content to
be used in the page and the page to be viewed apart from the application and
database queries which fill it out. For example:
<ul>
<li _foreach="$links as $link"><a title="<?= $link['title'] ?>" href="<?=
$link['href']" _echo="$link['text']">My Dummy Link</a></li>
<li _remove=""><a title="Dummy Link" href="#">Another Dummy Link</a></li>
<li _remove=""><a title="Dummy Link" href="#">Another Dummy Link</a></li>
</ul>
Would give you some links in a list that you could use to style and test in
a browser without PHP. Then use it with the template system and it makes the
links dynamic.
It's PHP 4 and 5 compatable, but I just use it for myself. If anyone is
interested in using it I can put it online and document it this weekend for
use. It's called Blueprint. If there were those that wanted to add to it we
could make it an open source project and get others helping with it. It's
pretty simple.
--
Jacob Wright
Within Code LLC
More information about the UPHPU
mailing list