Skip to content

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.

php
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 ​

html
<h1>{{ $name }}</h1>          <!-- Escaped output for XSS protection -->
<div>{!! $rawHtml !!}</div>   <!-- Raw unescaped output -->

Conditionals ​

html
@if ($role === 'Administrator')
    <p>Welcome, Admin!</p>
@else
    <p>Welcome, User.</p>
@endif

Loops ​

html
<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:

html
<!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:

html
@extends('layouts.app')

@section('content')
    <h1>Home Page</h1>
    <p>Welcome to our stateful application.</p>
@endsection

Including Subviews ​

Include reusable partial templates:

html
@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:

html
@island('Counter', ['count' => 0])

Mounts ​

Mount a client-side component container:

html
@mount('UserProfile', ['id' => 1])

Next Steps ​

Released under the MIT License.