Views
Nexphant provides an integrated, lightweight view compilation engine that supports Blade-like syntax directives and hybrid component mounting.
Rendering Templates
Use the global view() helper function inside your controller or route handlers. This function returns a ViewResponse which compiles and renders your HTML template.
use Nexphant\View\ViewResponse;
$app->get('/profile', function ($request, $response) {
return view('profile', [
'name' => 'Alice',
'role' => 'Administrator',
]);
});Templates are resolved from the resources/views directory by default. For example, view('profile') loads resources/views/profile.php.
Template Syntax & Directives
The view engine compiles Blade-like directives into native PHP:
Output variables
<h1>{{ $name }}</h1> <!-- Escaped output for XSS protection -->
<div>{!! $rawHtml !!}</div> <!-- Raw unescaped output -->Conditionals
@if ($role === 'Administrator')
<p>Welcome, Admin!</p>
@else
<p>Welcome, User.</p>
@endifLoops
<ul>
@foreach ($users as $user)
<li>{{ $user->name }}</li>
@endforeach
</ul>Template Layout Inheritance & Sections
Define a base layout in resources/views/layouts/app.php:
<!doctype html>
<html>
<head>
<title>My App</title>
</head>
<body>
<div class="content">
@yield('content')
</div>
</body>
</html>Extend it in resources/views/home.php:
@extends('layouts.app')
@section('content')
<h1>Home Page</h1>
<p>Welcome to our stateful application.</p>
@endsectionIncluding Subviews
Include reusable partial templates:
@include('partials.sidebar')Hybrid Rendering (Islands & Mounts)
Nexphant views support embedding interactive client-side components directly into server-side rendered templates:
Islands
Render an interactive client component with reactive states:
@island('Counter', ['count' => 0])Mounts
Mount a client-side component container:
@mount('UserProfile', ['id' => 1])