, (*1)
A light-weight template engine
, (*2)
Installation
PHP versions supported: 7.0, 7.1 and 7.2, (*3)
Install with composer: (recommended), (*4)
composer require transfiguration/transfiguration 1.*
require 'vendor/autoload.php';
use Transfiguration\Transfiguration;
Download latest realease: here, (*5)
Usage
$transfiguration = new Transfiguration;
// Setting template html
$transfiguration->html($templateHtml);
// Setting template variables
$transfiguration->data($templateData);
// Setting template base path for require and include.
$transfiguration->requirePath($templatePath);
Rendering template
This function is printing template html into the page., (*6)
$transfiguration->render();
Exporting template
This function returns executed template html., (*7)
$transfiguration->export();
Transfiguration hooks
This method extends Transfiguration templating engine functionality., (*8)
$transfiguration->hook("header", function($content="") {
return "<h1>{$content}</h1>";
});
usage in Transfiguration code, (*9)
{{ header 'This is a header.'}}
Transfiguration code
For loop
<ul>
{{ for $key : $value in var }}
<li>{{ echo $key . " " . $value}}</li>
{{endfor}}
</ul>
If statement
{{ if $loggedin == true}}
<b>User logged in!</b>
{{ elseif $guest == true }}
<b>User is guest!</b>
{{ else }}
<b>User not logged in!</b>
{{ endif }}
Print & Echo
{{echo "string"}}
or, (*10)
{{print "string"}}
Including files
{{ include 'base/footer.html' }}
or, (*11)
{{ require 'base/footer.html' }}
Setting variables
{{ var $varname = "varvalue" }}
Comments
{# This is a comment #}