duon/boiler

A PHP template engine that doesn't require you to learn a new syntax

Installs: 46

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/duon/boiler

0.1.2 2026-01-30 16:52 UTC

This package is auto-updated.

Last update: 2026-01-31 21:33:43 UTC


README

Software License Codacy Badge Codacy Badge Psalm level Psalm coverage

Boiler is a small template engine for PHP 8.5+, inspired by Plates. Like Plates, it uses native PHP as its templating language rather than introducing a custom syntax.

Key differences from Plates:

  • Automatic escaping of strings and Stringable values for enhanced security
  • Global template context, making all variables accessible throughout the template

Other highlights:

  • Layouts, inserts/partials, and sections (with append/prepend)
  • Optional HTML sanitization via symfony/html-sanitizer
  • Custom template methods and optional whitelisting of trusted value classes

Installation

composer require duon/boiler

Documentation

Start here: docs/index.md.

Quick start

Consider this example directory structure:

path
`-- to
	`-- templates
		`-- page.php

Create a template file at /path/to/templates/page.php with this content:

<p>ID <?= $id ?></p>

Then initialize the Engine and render your template:

use Duon\Boiler\Engine;

$engine = Engine::create('/path/to/templates');
$html = $engine->render('page', ['id' => 13]);

assert($html == '<p>ID 13</p>');

Common patterns

Render from multiple directories (optionally with namespaces):

$engine = Engine::create([
	'theme' => '/path/to/theme',
	'app' => '/path/to/templates',
]);

// Renders the first match (theme overrides app)
$engine->render('page');

// Force a specific namespace
$engine->render('app:page');

Control escaping:

$engine = Engine::create('/path/to/templates');
$engine->render('page');
$engine->renderUnescaped('page');

$engine = Engine::unescaped('/path/to/templates');
$engine->render('page');
$engine->renderEscaped('page');

Template helpers available via $this inside templates:

  • $this->layout('layout')
  • $this->insert('partial', ['value' => '...'])
  • $this->begin('name') / $this->append('name') / $this->prepend('name') / $this->end()
  • $this->section('name', 'default') / $this->has('name')
  • $this->esc($value) and $this->clean($html)

Run the tests

composer test
composer check
composer mdlint

License

This project is licensed under the MIT license.