PHPTAL is a PHP implementation of ZPT work. To be short, PHPTAL is a XML/XHTML template library for PHP.
While most web developpers continue to use ASP/JSP/PHP tags as the core language of their templates, the Zope community came with a refreshing idea named TAL. The idea was to move presentation actions inside XHTML attributes instead of using plain tags or elements.
Let's start with a simple PHP exemple (usually reproduceable in ASP/JSP):
<?php foreach ($values as $value): ?>
<div class="item">
<div class="title">
<?php if ($value->hasDate()): ?><?=$value->getDate()?><?php endif; ?>
<a href="<?= $value->getUrl() ?>"><?=
htmlentities($value->getTitle())
?></a>
</div>
<div class="content">
<?= htmlentities($value->getContent()) ?>
</div>
</div>
<?php endforeach; ?>
Let's have a look at the TAL way:
<div class="item" tal:repeat="value values">
<div class="title">
<span tal:condition="value/hasDate" tal:replace="value/getDate"/>
<a tal:attributes="href value/getUrl" tal:content="value/getTitle"/>
</div>
<div id="content" tal:content="value/getContent"/>
</div>
Now it's up to you to choose which version you prefer. Of course those tal:condition
, tal:replace
and tal:repeat
may looks strange when begining with TAL.
Just for fun let's modify this example:
<div class="item" tal:repeat="value values">
<div class="title">
<span tal:condition="value/hasDate" tal:replace="value/getDate">
2013-08-05
</span>
<a href="sample.html"
tal:attributes="href value/getUrl"
tal:content="value/getTitle">
My item title
</a>
</div>
<div class="content" tal:content="value/getContent">
This is a sample content which is replaced by the
real content when the template is run with real
data.
</div>
</div>
More in the manual.
htmlentities()
,gettext
or your own backend),