
Templum is an extremely lightweight, simple yet powerful and fast templating engine for PHP. It re-uses the power of PHP itself for rendering templates, but provides additional features making it easier to write templating code. Rendering templates using Templum is very fast; it approximates native PHP rendering speed for include() statements.
Templum's template syntax has the following features:
The following example shows most of Templum's custom syntax. You can also view its output.
<?php
require_once('templum.php');
// Define some data. This might as well have come from a database.
$username = 'jjohnson';
$accounts = array(
array('id'=>1, 'username'=>'jjohnson', 'realname'=>'John Johnson'),
array('id'=>2, 'username'=>'ppeterson', 'realname'=>'Pete Peterson'),
array('id'=>3, 'username'=>'jdoe', 'realname'=>'John Doe'),
);
// Create the Template engine with the base path for the templates.
$templum = new Templum('view');
// Set a universal variable which will be available in every template created
// using the template engine.
$templum->setVar('username', $username);
// Retrieve and render a template with the data in $accounts as a local
// variable and $username as a universal variable.
$tpl = $templum->template('account/list');
print($tpl->render(compact('accounts')));
?>
[[
if (!function_exists('helperBtnAction')) {
function helperBtnAction($action, $id, $icon) {
echo('<a href="?action='.$action.'&id='.$id.'">');
echo('<img src="ico/'.$icon.'.png" alt="'.$icon.'" border="0" />');
echo('</a>');
};
};
]]
<h1>User list</h1>
<p>Hello {{$username}}, here's a list of all the users:</p>
<div id="accounts">
@if (count($accounts) <= 0):
No accounts found.
@else:
<table>
<tr>
<th> </th>
<th>Username</th>
<th>Full naam</th>
</tr>
@foreach ($accounts as $account):
<tr>
<td>[[helperBtnAction('account.edit', $account['id'], 'edit')]]</td>
<td>{{$account['username']}}</td>
<td>{{$account['realname']}}</td>
</tr>
@endforeach
<tr>
<td>[[helperBtnAction('account.add', '', 'add')]]</td>
<td colspan="4"> </td>
</tr>
</table>
@endif
</div>