-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the official documentation for initphp/views — a small,
adapter-based view rendering layer for PHP 8.0+. Your application talks to
one tiny interface; an adapter turns queued view names plus data into a string.
Render with plain PHP, Blade or
Twig and switch engines without touching your call
sites.
composer require initphp/viewsuse InitPHP\Views\Facade\View;
use InitPHP\Views\Adapters\PurePHPAdapter;
View::via(new PurePHPAdapter(__DIR__ . '/views'));
echo view('dashboard', ['username' => 'admin']); // one view
echo view(['header', 'content', 'footer'], ['title' => 'Home']); // many, in orderRegister an adapter once; everything after that — the global view() helper and
the View facade — flows through it. Swap PurePHPAdapter for
BladeAdapter or TwigAdapter and the rest of
your code is unchanged.
| Symbol | Role |
|---|---|
View |
Static facade — register an adapter with via(), then forward every call to it. |
view() |
Global helper — the one-liner most code uses. |
ViewAdapterInterface |
The contract every adapter fulfils: setView, setData, getData, render. |
AdapterAbstract |
Abstract base with the shared queueing/data behaviour; extend it to build your own adapter. |
PurePHPAdapter · BladeAdapter · TwigAdapter
|
The three built-in adapters. |
ViewException · ViewAdapterException · ViewInvalidArgumentException
|
The exception types; all implement ViewExceptionInterface. |
- New to the package? Read Installation, then Quick Start.
- How do the facade and helper work? The View Facade & Helper.
- Choosing an engine? Compare the adapters below, then read its page: Pure PHP, Blade, Twig.
- Building your own engine? Custom Adapters.
- Looking for a specific method? The full API Reference.
- Practical patterns? Recipes.
| Adapter | Class | Engine | Needs | Best for |
|---|---|---|---|---|
| Pure PHP | Adapters\PurePHPAdapter |
Plain .php templates |
core only | zero-dependency rendering, small apps, partials |
| Blade | Adapters\BladeAdapter |
Laravel Blade | illuminate/view |
rich templating, layouts, directives |
| Twig | Adapters\TwigAdapter |
Symfony Twig | twig/twig |
sandboxed templates, designer-friendly syntax |
-
One interface, three engines. Your code depends on
ViewAdapterInterface, never on the concrete engine. Switching is a one-line change at bootstrap. -
A tiny surface. Queue views with
setView(), attach data withsetData(), render withrender(). That is the whole model. -
A global helper.
view($names, $data)covers the common case in one call, behind afunction_exists()guard so it never clashes with your framework. -
Safe Pure PHP rendering. Templates run in an isolated scope (no access to
$this), data cannot collide with the renderer's internals, and resolved paths are confined to the view directory. -
Reusable adapters.
render()clears its state afterwards, so one adapter instance serves many independent renders without leakage. -
One catchable exception family. Every error implements
ViewExceptionInterface. -
Extensible. Add your own engine by extending
AdapterAbstract.
| You call | You get |
|---|---|
view('home') |
renders home and returns the output |
view(['a', 'b'], $data) |
a then b, concatenated, sharing $data
|
view('profile', $object) |
object's public properties become template data |
View::getData('k', 'x') |
the value for k, or "x" if it is absent |
view('home') before View::via()
|
throws ViewException
|
view('home.php') (Pure PHP)
|
same as 'home' — the .php is not doubled |
view('dashboard/index') (Pure PHP)
|
views/dashboard/index.php |
view('missing') (Pure PHP)
|
throws ViewException — file not found |
view('../secret') (Pure PHP)
|
throws ViewException — outside the view directory |
- License: MIT
- Minimum PHP: 8.0
- Runtime dependencies: none (core); an engine per adapter you use
-
Packagist:
initphp/views - Source: github.com/InitPHP/Views
- Issues: github.com/InitPHP/Views/issues
- Discussions: github.com/orgs/InitPHP/discussions
If something in this wiki is unclear, wrong, or out of date, open an issue — documentation fixes are merged eagerly.
initphp/views · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Adapters
Reference
Guides
Other