Greg PHP View
, (*1)
A powerful View for PHP., (*2)
Table of Contents:
Requirements
Compilers
How It Works
First of all, you have to initialize a Viewer:, (*3)
$viewsDirectory = __DIR__ . '/views';
$viewer = new \Greg\View\Viewer($viewsDirectory);
Optionally, you can add a view compiler. For example a Blade Compiler specially created for the Viewer:, (*4)
// Turn it to a callable, to load only when using blade templates.
$viewer->addExtension('.blade.php', function () {
$compiledViewsDirectory = __DIR__ . '/compiled';
return new \Greg\View\ViewBladeCompiler($compiledViewsDirectory);
});
By default it will use Renderer as an instance of a template., (*5)
Note: If you want to use your own compiler, it has to be an instance of Compiler Strategy., (*6)
Now, you can render views where you want in your application., (*7)
Create a template file in the views directory. For example welcome.blade.php
:, (*8)
<html>
<body>
<h1>Hello, {{ $name }}</h1>
</body>
</html>
Use welcome
template in your application:, (*9)
$content = $viewer->render('welcome', [
'name' => 'Greg',
]);
echo $content;
Documentation
License
MIT © Grigorii Duca, (*10)
Huuuge Quote
, (*11)