Skip to content

sgdot/php-template

Repository files navigation

PHP Template

Native PHP template engine with autoescaping

Travis

Highlights

  • Automatic output escaping
  • Native PHP templates, no new syntax to learn
  • Framework-agnostic, will work with any project

Installation

PHP Template is available via Composer:

composer require sgdot/template

Usage

// 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:

Result

License

The MIT License (MIT). Please see License File for more information.

About

Native PHP template engine with autoescaping

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published