extro / view-engine
View engine
v1.0.0
2025-05-04 20:55 UTC
Requires
- php: ^8.2
Requires (Dev)
- phpunit/phpunit: ^9.6
README
Extro View Engine
Lightweight template engine for PHP with inheritance support.
📦 Installation
composer require extro/view-engine
🚀 Quick Start
- Create a base template: resources/views/layout.php
<!DOCTYPE html> <html> <head><?= $this->section('head') ?></head> <body> <?= $this->section() ?> </body> </html>
- Create a child template: resources/views/profile.php
<?php $this->extend('layout') ?> <?php $this->start('head') ?> <title>My profile</title> <?php $this->end() ?> <h1>Hello, <?= $this->get('name') ?>!</h1>
- Render in your code
use Extro\ViewEngine\View; use Extro\ViewEngine\ConfigInterface; // Implement your config (e.g., path to views) $config = new class implements ConfigInterface { public function getTemplateDir(): string { return __DIR__ . '/resources/views'; } }; $view = new View($config); echo $view->render('profile', ['name' => 'John']);
📚 Documentation
Template Inheritance
<!-- base.php --> <header><?= $this->section('header') ?></header> <main><?= $this->section() ?></main> <!-- page.php --> <?php $this->extend('base') ?> <?php $this->start('header') ?> Welcome Page <?php $this->end() ?> Main content goes here...
Data Handling
// Auto-escaped output (default) <?= $this->get('user_content') ?> // Raw HTML output (trusted content only) <?= $this->get('trusted_html', true) ?>