Download the PHP package webrium/view without Composer
On this page you can find all versions of the php package webrium/view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package view
Short Description Lightweight PHP template engine with hybrid static caching (no eval) for the Webrium framework.
License MIT
Homepage https://github.com/webrium/view
Informations about the package view
Webrium View
Lightweight PHP template engine with hybrid static caching (no eval, no DOMDocument) for the Webrium framework.
- GitHub: https://github.com/webrium/view
- Packagist: https://packagist.org/packages/webrium/view
- Install:
composer require webrium/view
Webrium View gives you a tiny template engine plus an optional static HTML cache. It compiles your templates to plain PHP files, never uses eval, and is designed to play nicely with modern frontend frameworks (Vue, Alpine, Livewire, etc.) by leaving their attributes untouched.
Features
- DOM-less streaming compiler – custom HTML parser, no
DOMDocument, so attributes like@click,:class,x-data,wire:click,hx-get, etc. are preserved exactly as written. - Hybrid static cache – render a page once, save it as static HTML with a TTL, and serve the static file on future requests.
- Blade-style directives –
@section,@yield,@component,@{{ }},@raw(),@json()/@tojs(),@php(). - Attribute-based control flow –
w-if,w-else-if,w-else,w-foron normal HTML elements. - Fine-grained opt-out –
w-skipto disable DOM-level processing in a subtree (useful when embedding another templating system). - Safe by default – escaped output for
@{{ }}, explicit opt-in to raw HTML and raw PHP.
Requirements
- PHP 8.1+
No extra PHP extensions are required; Webrium View uses only core functions.
Installation
1. Via Composer (recommended)
Then bootstrap it in your project:
The directories will be created automatically if they do not exist.
2. Manual install (alternative)
If you prefer not to use Composer, copy Engine.php, View.php, and Parser.php into your project, keep the Webrium\View namespace, and load them via your own autoloader or simple require statements.
Quick Start
1. Simple render
views/hello.php
public/index.php
2. Layout + section example
views/layouts/main.php
views/pages/home.php
public/index.php
Template Syntax & Directives
Webrium View uses a custom streaming HTML parser (not DOMDocument). It scans your HTML, rewrites special attributes and directives into plain PHP, and leaves everything else alone.
Escaped output – @{{ ... }}
Escaped output is the default:
Compiles to:
Raw output – @raw(...)
Use raw output only when you are sure the content is safe:
Compiles to:
Raw PHP – @php(...)
You can inject raw PHP (enabled by default):
If you want to disable this directive for security reasons:
Any use of @php(...) after that will throw a ViewTemplateException.
JSON / JavaScript – @json(...) and @tojs(...)
Both directives are equivalent and produce json_encode'd output:
You can also use them inside attributes:
Layouts – @section, @endsection, @yield
Child view
Layout
Available helpers in Webrium\View\View:
Components – @component(...)
Or call it directly from PHP:
Loops – w-for
Use w-for on an element to generate a foreach:
Compiles to:
Conditionals – w-if, w-else-if, w-else
Compiles to:
Disabling processing in a subtree – w-skip
Add w-skip to any element to disable DOM-level processing for that element and all its descendants:
Behavior:
w-if,w-for,w-else-if, andw-elseinside this subtree are not converted to PHP.- The
w-skipattribute itself is removed from the final HTML. - Inline directives such as
@{{ $something }}still work in text nodes.
Useful when embedding another frontend framework's attributes:
<script> / <style> behavior
Contents are treated as raw text (not parsed as nested HTML):
- By default, inline directives inside
<script>/<style>do work. - If you put
w-skipdirectly on the<script>or<style>tag, nothing inside is processed and the contents are emitted verbatim.
Hybrid Static Cache
Signature:
Cache TTL constants
You can also override the default TTL:
Mode 1 – Direct data (always re-render)
Mode 2 – Lazy factory (only run when needed)
The factory is called only when no valid cache exists or the cache has expired.
Mode 3 – Read-only access
Returns false if no valid (non-expired) cache exists.
Directory Helpers & Clearing Caches
Error Handling
ViewException covers bad directories, missing view files, and I/O failures.
ViewTemplateException covers invalid w-for / w-if syntax, unclosed tags, unmatched directive parentheses, and disabled @php() usage.
Editor.js Integration
Webrium View includes a built-in parser that converts Editor.js JSON output to clean HTML.
Supported block types
| Block type | Output |
|---|---|
paragraph |
<p> |
header |
<h1>–<h6> |
list |
<ul> / <ol> |
nestedList |
Nested <ul> / <ol> |
image |
<figure><img></figure> |
quote |
<blockquote> |
code |
<pre><code> |
table |
<table> with optional <thead> |
delimiter |
<hr> |
embed |
<iframe> wrapper |
warning |
Alert <div> |
raw |
Verbatim HTML pass-through |
checklist |
<ul> with checkboxes |
linkTool |
Anchor card with optional image |
attaches |
Download link with file size |
personality |
Author card |
Basic usage
Then render it in a template:
Full example:
Custom CSS classes
Registering custom block handlers
Inline HTML sanitization
By default the parser allows common inline tags and strips everything else. To disable sanitization:
Note: The
rawblock type always passes HTML through as-is, regardless of thesanitizeflag.
Notes
- Webrium View does not use
eval; compiled templates are normal PHP files that arerequired. - All data passed into
render()is available both as individual variables ($user,$title, etc.) and as a$zogDataarray inside the template.
License
MIT
Contributing
Open issues and pull requests on GitHub. Ideas, bug reports, and feature suggestions are very welcome.