stefgodin / notmpl
Lightweight PHP template engine leveraging PHP native rendering and output buffers.
v0.6.0
2024-03-23 23:20 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^9.5
README
NoTMPL
A light-weight template-less rendering engine for PHP back-end devs.
- ☑ No dependencies
- ☑ Lightweight code base (< 1000 LOC)
- ☑ No cache directory
- ☑ No eval
- ☑ Composition of pages using components and slots
- ☑ Free from autoescaping
- ☑ Free from sandboxing
Installation
Install the library using composer:
composer require stefgodin/notmpl
Requirements
This library requires PHP 8.1+
Quick peek
<?php // index.php use StefGodin\NoTmpl\NoTmpl; require_once __DIR__.'/../vendor/autoload.php' $noTmpl = new NoTmpl(); echo $noTmpl->render('main.php', ['title' => 'My custom title']); /* <div>A header</div> <h1>My custom title</h1> <div> <div> <h2>My content</h2> </div> </div> <div>A footer</div> */
<?php // main.php use function StefGodin\NoTmpl\{component, component_end, use_slot, use_slot_end, esc_html as e}; /** * @var string $title */ ?> <?php component('page.php') ?> <?php use_slot('header') ?> <h1><?= e($title) ?></h1> <?php use_slot_end() ?> <div> <h2>My content</h2> </div> <?php component_end() ?> <div>A footer</div>
<?php // page.php use function StefGodin\NoTmpl\{slot, slot_end}; ?> <div>A header</div> <?php slot('header') ?> <h1>My normal title</h1> <?php slot_end() ?> <div> <?php slot() ?> <div>Some default content</div> <?php slot_end() ?> </div>
Documentation
Read the getting started guide if you are new.
Browse the documentation for examples and concepts.