I want to keep away my php codes from design, I would like to use a tpl file for designs
...and mix your tpl codes with "design"!
what's the difference then? :)
PHP itself is efficient templating system.
And nowadays most developers agreed that dividing your PHP code to business logic part and display logic part is most preferable way.
It can be very limited subset of PHP of course. You will need an output operator (<?=$var?>
) one, a condition <? if(): ?>...<? endif ?>
, a loop <? foreach(): ?>...<? endforeach ?>
and include.
An example of such a template:
<table>
<? foreach ($data as $row): ?>
<tr>
<td><b><?=$row['name'] ?></td>
<td><?=$row['date'] ?></td>
</tr>
<tr>
<td colspan=2><?=$row['body'] ?></td>
</tr>
<? if ($row['answer']): ?>
<tr>
<td colspan=2 valign="top">
<table>
<tr>
<td valign="top"><b>Answer: </b></td>
<td><?=$row['answer'] ?></td>
</tr>
</table>
</td>
</tr>
<? endif ?>
<? if($admin): ?>
<tr>
<td colspan=2>
<? if($row['del']): ?>
<a href="/gb/?action=undelete&id=<?=$row['id']?>">show</a>
<? else: ?>
<a href="/gb/?action=delete&id=<?=$row['id']?>">hide</a>
<? endif ?>
<a href="/gb/?action=edit&id=<?=$row['id']?>">edit</a>
</td>
</tr>
<? endif ?>
<? endforeach ?>
</table>