initphp/views is a thin, adapter-based rendering layer. Your application
talks to one small interface — ViewAdapterInterface — and an adapter turns
queued view names plus data into a string. Swapping the rendering engine
(plain PHP, Blade, Twig, or your own) never touches your call sites.
- Getting started — install, register an adapter, render.
- The facade and the
view()helper — how the static entry point and the global helper work. - Adapters
- Writing a custom adapter — the
ViewAdapterInterfacecontract andAdapterAbstract. - Exceptions
use 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', 'body', 'footer'], ['title' => 'X']); // many, in orderEvery adapter follows the same three-step lifecycle:
- Queue views with
setView()(names are appended, in order). - Attach data with
setData()(arrays or objects; repeated keys overwrite). - Render with
render(), which returns the concatenated output and then clears the queue and data so the adapter can be reused.
AdapterAbstract implements steps 1, 2 and the data accessor for you; a
concrete adapter only implements render().