Re: template engine...why???
| From: | Robert Cummings | Date: | Wed, 30 Apr 2003 14:42:57 +0000 |
| Subject: | Re: template engine...why??? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145781@lists.php.net to get a copy of this message | ||
I have to disagree with this opinion :) While PHP supports the basics of a
templating system, it does not constitute a serious templating system. One
of the large advantages of a templating system is hiding the complexity of
logic with simple embedded macros/tags/whatever. When doing so a person
without any knowledge of PHP can easily make use of the logic. Take for
example templating system that uses a simple XML style and outputs an HTML
<img/> tag. One might expect to see something like:
<myImage src="/foo.gif"/>
And the template compiler would output:
<img src="/foo.gif" height="23" width="45" />
Now I know you said this would be slow, but methinks you are assuming a
run-time templating engine. If so then sure, it ultimately boils down to
more overhead; however, if it is a compiler which runs once producing the
output then even caching mechanisms via PHP cannot match the speed of
retrieving and outputting the image dimensions. This is a very trivial
example, there is plenty of room for much more powerful simplification
using a templating engine. I do concede the point though that right now,
most templating languages aren't exactly so simple to use :)
Cheers,
Rob.
Rasmus Lerdorf wrote:
>
> Don't discount the fact that PHP was originally a templating system, and
> it still is! My contention is that any general-purpose templating system
> will eventually evolve to become PHP because you simply cannot solve all
> templating problems without some presentation-level logic and once you add
> the first signs of template-level logic, you will eventually turn into
> PHP.
>
> You can of course simplify the problem and limit the scope so that you
> only address a thin slice of the problem. But you don't really need to
> layer a templating system on top of PHP for that. You just need to apply
> a little bit of discipline and come up with a sane architecture. Take
> this, for example:
>
>
> http://talks.php.net/presentations/slides/intro/php_app_arch.png
>
> An illustration of using this 4-layer architecture is here:
>
> http://talks.php.net/show/nytips/2
>
> (Yes, I know it looks like crap in IE. View it using Mozilla)
>
> If you can't run Mozilla, you can view the plain PDF version here:
>
> http://lerdorf.com/nytips.pdf
>
> So, please, before you start layering slow templating systems on top of
> PHP, have a look at using PHP itself as your templating system. If you
> are at all concerned about performance you need to seriously consider an
> approach like this.
>
> -Rasmus
--
.---------------------------------------------.
| Worlds of Carnage - http://www.wocmud.org |
:---------------------------------------------:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the |
| stuff of nightmares grasp for your soul. |
`---------------------------------------------'