extro/view-engine

v1.0.0 2025-05-04 20:55 UTC

This package is auto-updated.

Last update: 2025-06-04 21:12:06 UTC


README

Latest Version License

Extro View Engine

Lightweight template engine for PHP with inheritance support.

📦 Installation

composer require extro/view-engine

🚀 Quick Start

  1. Create a base template: resources/views/layout.php
<!DOCTYPE html>
<html>
<head><?= $this->section('head') ?></head>
<body>
    <?= $this->section() ?>
</body>
</html>
  1. 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>
  1. 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) ?>