zaplate
PHP is an HTML template engine. This only sugars it up a bit, enough
to render mostly-static HTML, which is all zap*
ever needs due to
it being RESTful-oriented.
Use other full-blown templating engines for rendering complex dynamic HTML.
Installation
Install it from Packagist:
$ composer -vvv require bfitech/zaplate
Sample Usage
template.php
<p><?php echo $group ?></p>
<ul>
<?php foreach ($members as $member): ?>
<li><?php echo $member ?></li>
<?php endforeach; ?>
</ul>
renderer.php
<?php
require __DIR__ . '/vendor/autoload.php';
class Filter {
public function whoami($name) {
if (is_string($name))
return $name;
return array_map(function($iname){
if (stripos($iname, 'jekyll') !== false)
return 'Mr Hyde';
return $iname;
}, $name);
}
}
BFITech\ZapTemplate\Template::load('template.php', [
'group' => "Extraordinary Gents",
'members' => [
'Allan Quatermain',
'Henry Jekyll',
],
], [
[(new Filter), 'whoami'],
]);
Run it:
$ php renderer.php
<p>Extraordinary Gents</p>
<ul>
<li>Allan Quatermain</li>
<li>Mr Hyde</li>
</ul>
PROTIP: If you want to minify the HTML on production, run your
template file through yourmy favorite
minifier prior to
rendering it, e.g.:
$ [ ! -f template.orig.php ] && cp template.{,orig.}php
$ php -w template.orig.php | \
> html-minifier \
> --collapse-whitespace \
> --trim-custom-fragments > \
> template.php
Aaand ... huzzah!
$ php renderer.php
<p>Extraordinary Gents</p><ul><li>Allan Quatermain</li><li>Mr Hyde</li></ul>
Documentation
Documentation available with:
$ doxygen
$ x-www-browser docs/html/index.html