Firstly, apologies as some of my code in my previous example appeared to be missing (fixed now). Not sure what happened there but I was copying and pasting a bit.
I had no trouble learning the limited syntax available for use with the patTemplate engine (took one day of reading and that was about it). As usual, I learned what I required and ignored the rest until such time as it became needed.
You say people hardly ever need all the functionality of the template engines. How many of the PHP functions do you use out of all that are available? They only slow you down if you actually run code through them. There's no harm with them being included at start up.
You seem to think templates are slow. I agree, by their nature, they are slower than straight-forward PHP, but to say they are slow is simply incorrect. To prove my point take a look here:
http://events.lexusonwersclub.co.uk
User: testacc
Pass: testacc (you won't be able to add anything, obviously)
Does it seem slow to you? The complete event management tool is written using patTemplate and PHP.
It seems you are missing an important point though. This isn't about how easy it is for you to read, learn the syntax for, and understand, it's how easy it is for someone, who has never had any experience of PHP, is able to design the HTML page (using your results from the server side processing). They don't even have to learn the template syntax. They simply need to know what bits display what and style and integrate them accordingly. I find it surprising that you think jumping in and out of php tags within a large HTML document to be easier to read, remembering that such HTML output could be embedded very deep within surrounding PHP code. It simply begs for a syntactical error to rear it's ugly head. So easy to miss off the closing } (<?php } ?>), portability and/or completely changing the layout of the HTML document is out of question unless you know which closing } is for which part of the code and having to edit echo, print, printf, or heredoc statements (perhaps negotiating double quoting, etc).
Is this something you expect a HTML/graphics only developer to do? Personally I don't.
So, the code to construct the table in my previous example would be:
PHP Code:
for ($i = 0, $max = sizeOf($arrData); $i < $max; ++$i) {
$tpl->addVar('myTable', 'CATEGORY', $arrData[$i]['title']);
$tpl->addVar('myTable', 'STATUS', $arrData[$i]['status']);
$tpl->addVar('myTable', 'ID', $arrData[$i]['link']);
$tpl->parseTemplate('myTable', 'a');
}
$tpl->displayParsedTemplate('myTable');
Code:
<!-- HTML file -->
<!-- No PHP code at all -->
<table>
<patTemplate:tmpl name="myTable">
<tr>
<td>{CATEGORY}</td>
<td>{STATUS}</td>
<td><a href="order.php?id={ID}">Order Me</a></td>
</tr>
</patTemplate:tmpl>
</table>
If the designer then chooses to not display the results in a table, but now as a heading, paragraph and straight-forward link, they need only modify the template and move the placeholders
Code:
<h2>{CATEGORY}</h1>
<p>Presently this item is {STATUS}<br />(<a href="order.php?{ID}">Click to order</a>)</p>
Absolutely no contact with any PHP was required to change the layout, no editing of echo tags, print tags, printf statements, heredocs, etc.
The point of templates is not about the PHP designer; it's about the HTML developer. Separating the business rules from the presentation.
I stress again my final point of before. Templates are not for everbody and every application. However, it is simply wrong to say there is never a need for them in any case, for anyone.
Bookmarks