Skip to content

PHP is an HTML template engine.

License

Notifications You must be signed in to change notification settings

bfitech/zaplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1088343 · Feb 5, 2020

History

23 Commits
Jun 16, 2019
Jun 16, 2019
May 6, 2017
Feb 5, 2020
Jun 16, 2019
Feb 5, 2020
Feb 5, 2020
Mar 29, 2017
Jun 16, 2019
Feb 5, 2020
Jun 16, 2019
Jun 16, 2019
Apr 6, 2017

Repository files navigation

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.

Latest Stable Version Latest Unstable Version Build Status Codecov GitHub license


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