memran / marwa-view
A thin, developer-friendly PSR-compliant View Engine built on top of Twig with PSR-16 caching. Part of the MarwaPHP ecosystem.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/memran/marwa-view
Requires
- php: ^8.1
- psr/simple-cache: ^3.0
- symfony/translation: ^7.3
- twig/twig: ^3.21
Requires (Dev)
- memran/php-testify: ^1.0
- symfony/var-dumper: ^7.0
This package is auto-updated.
Last update: 2025-10-26 06:10:12 UTC
README
A modern, developer-friendly View Engine built on top of Twig, designed for best DX, clean integration, and PSR-16 fragment caching — without ever exposing Twig internals.
⚙️ Part of the MarwaPHP ecosystem.
🚀 Features
- ✅ Thin wrapper — hides Twig from your app code
- ⚡ PSR-16 fragment caching (
fragment('key', ttl, producer)) - 🧠 Familiar DX (
View::render(),View::share(),view()in templates) - 🔒 PSR-12, SOLID, framework-agnostic
- 💾 Automatic cache directory management
- 🧩 Extensible via custom Twig Extensions
- 🧰 Debug-safe with strict variables in dev mode
📦 Installation
composer require memran/marwa-view
Quick Start
use Marwa\View\View; use Marwa\View\ViewConfig; use Symfony\Component\Cache\Simple\Psr16Cache; // or any PSR-16 cache $config = new ViewConfig( viewsPath: __DIR__ . '/views', cachePath: __DIR__ . '/storage/views', debug: true, fragmentCache: new Psr16Cache() // optional ); $view = new View($config); $view->share('appName', 'EnetFlow'); // Render a view echo $view->render('home/index', ['title' => 'Welcome']);
Example Template
{# views/home/index.twig #}
<!DOCTYPE html>
<html>
<head><title>{{ title }} - {{ appName }}</title></head>
<body>
<h1>Hello {{ title }}</h1>
{{ view('components/footer')|raw }}
{# Cache fragment for 5 min (300s) #}
{{ fragment('sidebar', 300, {
template: 'partials/sidebar',
data: { name: 'Emran' }
})|raw }}
</body>
</html>
Integrating with a Container
$container->add(Marwa\View\ViewInterface::class, function() { $cfg = new ViewConfig( viewsPath: base_path('resources/views'), cachePath: storage_path('views'), debug: env('APP_DEBUG', false) ); return new View($cfg); });
Testing
composer test
Requirements
- PHP 8.1 +
- twig/twig ^3.21
- psr/simple-cache ^3.0
License
MIT © Mohammad Emran