These comments are in regards to the article \'All About Smarty - The PHP Template Engine\'.

Although it's an excellent article something doesn't feel quite right when i read about Smarty ( or any other template-engine for PHP )

Because in essence PHP is already a template-language. The design of the language itself isn't that interesting ( flamewar alert ) it uses the best of all languages to pruduce the fastes results for its goal, which is to be the best webscripting language. What PHP makes interesting IMO are the modules, which allows you to do all sort of things.

As noted in the FAQ of Smarty, most template-engines are nothing more than a wrapper around a filereading and string substitution wrapper. I guess most of you already tried to write a simple template-parser script in PHP. THere are some smart feattures that makes Smarty preferable compared to other solutions, one of the most significant ones is that it compiles to PHP code. But the question remains:

Why would i want to have a PHP script that transforms my data into a presentation form using a language which goal is to do that.

For example, i can use simple control structures in Smarty:

PHP Code:
{if $name eq "Fred"}
You are not allowed here
Welcome, <font color="{#fontColor#}">{$name}!</font>
now what is the difference with the if/else structure written in PHP, and more important, what is the advantage?:

PHP Code:
if ( $name == "Fred ) {
    echo "
You are not allowed here";
} else {
    echo "
Welcome, <font color='$fontColor'>$name!</font>";

If you look at profesional template solutions, you can already use a scripting language like Perl or Python in your templates, so if your point is that it's easier to learn for your (template)'s not.

But enough about implementation, the real point why you would use a template-engine is that you wanna have a proper shifting of your data and your presentation. You want to
transform your data into a view ( or presentation ) If you only need one view of your data, let's say a html presentation of your data like a website, a combination of PHP and a template-parser would be enough, but let's say i want different views on the same data. You'll soon hit some limitations.

A website can profit from a framework that uses different layers. In most situations, your view is gonna be generated from a fixed part of your data. Per page, a template is gonna be made and filled with your data-set. Whenever your presentation is gonna be altered and more data is needed, your ****ed. The code to deliver that data has to be altered as well, because your template is generated.

A solution would be to use an XML-XSL solution. First, your presentation is even more independent then your data. The presentation itself can use other data to make new combinations.

For clarity, it's often better to setup your structure not as a collection of HTML files. You'll often see a 1-on-1 mapping from data producers to HTML pages. With XML-XSL that isn't the case at all.

The beauty is that you concentrate on what data you have to offer instead what view you need. You don't have to worry on what presentation you gonna offer or the data the presentation might need. Your solution will be XML-based and with the help of XSLT you can transform data to (X)HTML. You could even combine differen data sources to achieve this.

Major advantage: you're working on an atomic level instead of concentrating about delivering your data.

I do have to agree it's an extra complicating factor. I'm certainly not the one to say webdesigners should write XSLT stylesheets. However, the framework laid out here using a clear seperation between the data you have to offer and the HTML presentation on the web certainly adds another level of professionalism and in the long run will be worthwile.

How is that for brainfood?