Skip to content

⚙️ A lightweight templating engine library in php

License

Notifications You must be signed in to change notification settings

svichas/Transfiguration

Repository files navigation

A light-weight template engine

Travis GitHub license Packagist

Installation

PHP versions supported: 7.0, 7.1 and 7.2


Install with composer: (recommended)

composer require transfiguration/transfiguration 1.*
require 'vendor/autoload.php';
use Transfiguration\Transfiguration;

Download latest realease: here


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.

$transfiguration->render();

Exporting template

This function returns executed template html.

$transfiguration->export();

Transfiguration hooks

This method extends Transfiguration templating engine functionality.

$transfiguration->hook("header", function($content="") {
	return "<h1>{$content}</h1>";
});

usage in Transfiguration code

{{ 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

{{print "string"}}

Including files

{{ include 'base/footer.html' }}

or

{{ require 'base/footer.html' }}

Setting variables

{{ var $varname = "varvalue" }}

Comments

{# This is a comment #}

About

⚙️ A lightweight templating engine library in php

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages