Important
This repository is read-only.
Development happens in the Annabel monorepo: https://github.com/codemonster-ru/annabel
Issues and pull requests should be opened there.
A core for rendering views in PHP applications.
The package itself doesn't contain any engines; they are included in separate packages:
codemonster-ru/view-php- PHP templatescodemonster-ru/view-ssr- SSR for Vue/React- (future) Twig, Blade, and others
composer require codemonster-ru/viewuse Codemonster\View\View;
use Codemonster\View\Locator\DefaultLocator;
use Codemonster\View\Engines\PhpEngine; // package: codemonster-ru/view-php
$locator = new DefaultLocator([__DIR__ . '/resources/views']); // can be an array of paths
$engine = new PhpEngine($locator, 'php'); // default extension: php
$view = new View(['php' => $engine], 'php');
// Render template
echo $view->render('emails.welcome', ['user' => 'Vasya']);
// Looks for: resources/views/emails/welcome.php
// Access the locator of the default engine (added in v2.2.0)
$defaultLocator = $view->getLocator();
$defaultLocator->addPath(__DIR__ . '/vendor/package/views');
// Register namespaced view paths (added in v2.3.0)
$view->addNamespace('admin', __DIR__ . '/resources/views/admin');
echo $view->render('admin::dashboard', ['user' => 'Vasya']);- Engine-agnostic core
- Support for multiple engines (
PhpEngine,SsrEngine,TwigEngine, etc.) - Unified
EngineInterfaceinterface - Easy integration with frameworks (e.g., Annabel)
You can run tests with the command:
composer test