Getting Started
Zing uses .zing files as templates and compiles them to PHP before rendering.
Installation
composer require zi/zing
Zing requires PHP ^8.2.
Creating an engine
use Zing\Engine;
$engine = new Engine(
viewPath: __DIR__ . '/resources/views',
cachePath: __DIR__ . '/storage/zing-cache',
);
viewPath is the directory containing your .zing templates. cachePath is where Zing stores compiled PHP.
Rendering a template
echo $engine->render('pages.settings', ['user' => $user]);
Template names use dot notation:
pages.settings
maps to:
resources/views/pages/settings.zing
The variables passed as the second argument are made available to the template.
During development
When you're actively editing templates, you might want to disable caching so changes are immediately visible:
use Zing\Flags;
$engine = new Engine(
viewPath: __DIR__ . '/resources/views',
cachePath: __DIR__ . '/storage/zing-cache',
flags: Flags::NO_CACHE,
);
See Flags for other options.