Download the PHP package lighthouse/view without Composer
On this page you can find all versions of the php package lighthouse/view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lighthouse/view
More information about lighthouse/view
Files in lighthouse/view
Package view
Short Description PHP Template Engine for the Lighthouse framework
License MIT
Informations about the package view
Lighthouse View
A simple, powerful PHP template engine for the Lighthouse framework.
Installation
Requirements
- PHP 8.2 or higher
Features
- PHP-based templates (no new syntax to learn)
- Layouts with sections
- Partials/includes
- Automatic HTML escaping
- Global shared data
- Dot notation for view paths
Quick Start
Basic Rendering
views/welcome.php:
Escaping
Always escape user data to prevent XSS attacks:
Layouts
Create a layout template:
views/layouts/main.php:
Extend the layout in your view:
views/users/index.php:
Partials
Include reusable components:
views/partials/alert.php:
Usage:
Or capture the output:
Shared Data
Share data across all views:
Access in any template:
Dot Notation
View paths use dot notation:
Check View Exists
API Reference
View
| Method | Description |
|---|---|
render(string $view, array $data) |
Render a view template |
partial(string $partial, array $data) |
Render and return a partial |
include(string $partial, array $data) |
Render and echo a partial |
extends(string $layout) |
Set layout for current view |
section(string $name) |
Start capturing a section |
endSection() |
End section capture |
yield(string $name, string $default) |
Output section content |
hasSection(string $name) |
Check if section exists |
share(string\|array $key, mixed $value) |
Share data globally |
getShared(?string $key) |
Get shared data |
escape(string $value) |
Escape HTML entities |
e(string $value) |
Alias for escape() |
json(mixed $value) |
Safe JSON encoding |
exists(string $view) |
Check if view file exists |
getBasePath() |
Get views base path |
setBasePath(string $path) |
Set views base path |
Template Variables
Inside templates, these variables are available:
$view- The View instance (for helpers)- Any data passed to
render()orpartial() - Any globally shared data
Testing
License
MIT License. See LICENSE for details.
Part of the Lighthouse Framework
This package is part of the Lighthouse Framework, an educational PHP framework designed to teach how modern frameworks work internally.