View
View resolves a view name against a configured root directory and returns a
Response. There's no implicit variable injection — every variable a view sees arrived
via an explicit share() call, a render() argument, or a composer.
Methods
View::configure(string $viewPath): void // once, from config/bootstrap.php
View::render(string $view, array $data = []): Response
View::share(string $key, mixed $value): void // available to every view rendered afterward
View::composer(string $view, callable $callback): void // runs just before $view renders
View::exists(string $view): bool
Rendering pipeline
Fixed and sequential, no runtime magic: resolve the view file → merge local data (the
render() array) with shared data (from share()) → run any registered
composer for that view → render the view's content → apply its layout, if it sets one → return the
Response.
Usage
use Monad\Clarity\Services\View;
Route::get('/users', function () {
$users = DB::run('SELECT id, email FROM users')->fetchAll();
return View::render('Users/index', ['users' => $users]);
});
A view sets $layout = 'Layouts/main'; at its own top to render inside a layout — this
site's every page does exactly that (see app/views/Docs/Article.php in the repo).
Next steps
- Request/Response Lifecycle — where
View::render()fits in a real request.