Looking at using a template system for a new project, it’s only a small site and don’t want to use the overhead and ‘complexity’ of smarty. I don’t really like template systems that force you to make use of another language just to make it easier for designers (apparently).
Something like this http://www.namepros.com/code/517342-php5-template-class.html is what Im looking at but something which is a bit more robust and proven.
Advertisement
Answer
PHP by itself is already a template engine. So why not cut out the overhead a template engine written in a template engine brings with it and just use PHP then?
<h1><?php echo $pageTitle ?></h1>
<div>
<ul>
<?php foreach($items as $item): ?>
<li><?php echo htmlentities($item); ?></li>
<?php endforeach; ?>
</ul>
</div>
If you need added functionality, consider using ViewHelper, e.g. small functions that encapsulate stuff like adding links names or translating, e.g.
<table>
<?php foreach($items as $key => $item): ?>
<tr class="<?php echo oddEven($key)?>">
<td><?php echo productLink($item->id); ?></td>
<td><?php echo translate($item->description); ?></td>
</tr>
<?php endforeach; ?>
</table>
If that’s too verbose, have a look at HEREDOC and NOWDOC syntax and if this is still not what you are looking for, here is a list of some template engines:
- http://www.webresourcesdepot.com/19-promising-php-template-engines/
- http://en.wikipedia.org/wiki/Web_template_system#Server-side_systems
Or, if you feel experimental, have a look at XHP, Facebook’s extension approach to a Template engine: