Templating
, (*1)
Requires PHP 5.3+, (*2)
A super lightweight templating system that makes PHP templating awesome., (*3)
Basic usage
Starting with a really basic application which has the following layout:, (*4)
โโโ templates
โ โโโ greeting.phtml
โโโ composer.json
โโโ index.php
The composer.json file has stuartwakefield/templating in the the require map:, (*5)
{
"require": {
"stuartwakefield/templating": "0.1.0a"
}
}
The template file templates/greeting.phtml has the following content:, (*6)
<p>Hey there, <?= $this->name ?>!</p>
The index.php script:, (*7)
fill(array(
'name' => 'Bob'
));
echo $result; // Hey there, Bob!, (*8)
```
Simple as that!
## Presenters
The really cool thing with this templating library is that you can start to use presenter objects with your templates effortlessly.
Lets set up a basic presenter `src/Presenter.php` and lets assume you have set up composer to autoload the class:
```php
name = $name;
}
function greet() {
return 'Hello, ' . $name . '! You are logged in.';
}
}
```
Then in a new template `templates/account.phtml`:
```php
= $this->greet() ?></p>
, (*9)
Our updated index.php looks like this:, (*10)
<?php
require_once 'vendor/autoload.php';
use Templating\Template;
$template = new Template('templates/account.phtml');
$presenter = new Presenter('Khan');
$result = $template->fill($presenter);
echo $result; //
Hello, Khan! You are logged in., (*11)