Native PHP template engine with autoescaping
- Automatic output escaping
- Native PHP templates, no new syntax to learn
- Framework-agnostic, will work with any project
PHP Template is available via Composer:
composer require sgdot/template
// Create new Template instance
$templates = new Sgdot\Template\Engine('/path/to/templates');
// Render a template in a subdirectory
echo $templates->render('partials/header');
// Render a template
echo $templates->render('profile', ['name' => 'Jonathan']);
Function __raw
disable autoescaping
// index.php
<?php
require __DIR__ . '/vendor/autoload.php';
$templates = new Sgdot\Template\Engine(__DIR__ . '/templates');
echo $templates->render('example-template', ['value' => '<strong>Hello world</strong>']);
// example-template.php
<p>Escaped: <?= $value ?></p>
<p>Raw: <?= __raw($value) ?></p>
Result:
The MIT License (MIT). Please see License File for more information.