1. Go to this page and download the library: Download devanych/view-renderer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
devanych / view-renderer example snippets
use Devanych\View\Renderer;
$renderer = new Renderer('/path/to/root/directory/of/views');
$content = $renderer->render('path/to/view/file', [
'variableName' => 'the value of a variable of any type',
]);
echo $content;
// The `$variableName` variable will now be available inside files.
$renderer->addGlobal( 'variableName', 'the value of a variable of any type');
// For all views and layouts, the value is `$author` will equal `Boby`
$renderer->addGlobal( 'author', 'Boby');
// Only for the `blog/page` view, the value is `$author` will be equal to `John`
$renderer->render('blog/page', [
'author' => 'John',
]);
// or assign a value in the view
$author = 'John';