1. Go to this page and download the library: Download stougeiro/view 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/ */
stougeiro / view example snippets
use STDW\View\Engine\PhpEngine;
use STDW\View\ViewConfig;
use STDW\View\ViewManager;
$config = new ViewConfig([
'storage' => __DIR__ . '/views',
'extension' => '.php', // optional (default)
'aliases' => [ // optional
'admin' => __DIR__ . '/views/admin',
],
]);
$view = new ViewManager($config, new PhpEngine());
// Data shared with every render
$view->share(['site' => 'My App', 'locale' => 'pt_BR']);
// Dot notation → {storage}/pages/about.php
echo $view->render('pages.about', ['title' => 'About']);
// Alias → {alias}/sidebar.php
echo $view->render('admin:sidebar');
// Aliases can also be registered at runtime
$view->alias('blog', __DIR__ . '/blog/views');
echo $view->render('blog:post', ['slug' => 'hello-world']);