nexphant/view
Lightweight view engine with Blade-like syntax and hybrid rendering support.
Install
bash
composer require nexphant/viewBasic Usage
Render templates using the global view() helper.
php
use function Nexphant\View\view;
// Return a ViewResponse containing rendered HTML
return view('home', ['title' => 'Nexphant Framework']);Create a factory directly when you need custom paths:
php
use Nexphant\View\ViewFactory;
$views = new ViewFactory(
basePath: base_path('resources/views'),
cachePath: storage_path('views')
);
$html = $views->make('dashboard.index', ['user' => $user])->render();
$raw = $views->raw('emails/welcome');View objects are immutable-style renderables:
php
$view = $views->make('profile')->with('user', $user);
return $view->render();Template Directives
The compiler supports typical template directives:
blade
<!-- Variables -->
{{ $title }} <!-- Escaped Output -->
{!! $rawHtml !!} <!-- Raw Output -->
<!-- Conditionals -->
@if ($isAdmin)
<p>Admin panel</p>
@endif
<!-- Loops -->
@foreach ($users as $user)
<li>{{ $user->name }}</li>
@endforeach
<!-- Includes and Inheritance -->
@extends('layouts.app')
@section('content')
<h1>Welcome</h1>
@endsection
@include('partials.sidebar')Compiled templates are written to the configured cache path. Dot notation such as dashboard.index resolves to nested template files under the view base path.
View Responses
ViewResponse wraps rendered HTML for framework handlers:
php
use Nexphant\View\ViewResponse;
return new ViewResponse($views->make('home', ['title' => 'Nexphant']));Hybrid Islands & Mounting
Embed client-side reactive components or islands into server-rendered pages:
blade
<!-- Render a client component with interactive state -->
@island('Counter', ['count' => 0])
<!-- Mount a standard component -->
@mount('UserProfile', ['id' => 1])Global Helpers
| Helper | Description |
|---|---|
view(string $view, array $data = []) | Creates a ViewResponse from a template. |
raw(string $path) | Returns the raw contents of a view file. |
nx(mixed $value) | Escapes values to prevent XSS. |
nx_json(mixed $data) | Encodes data to JSON and escapes it. |
nx_asset(string $path) | Formats an asset path URL. |
nx_island(string $name, array $props) | Generates an interactive island HTML container. |
nx_mount(string $name, array $props) | Generates a mountable component HTML container. |
