1. Go to this page and download the library: Download brightnucleus/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/ */
brightnucleus / view example snippets
namespace View\Example;
use View\Example\App;
use BrightNucleus\View;
use BrightNucleus\View\Location\FilesystemLocation;
$folders = [
App::ROOT_FOLDER . '/child-theme/templates',
App::ROOT_FOLDER . '/parent-theme/templates',
App::ROOT_FOLDER . '/plugin/templates',
];
foreach ($folders as $folder) {
Views::addLocation(new FilesystemLocation($folder));
}
namespace View\Example;
use View\Example\User;
use BrightNucleus\Views;
echo Views::render('welcome-user', [ 'userId' => User::getCurrentId() ]);
namespace View\Example;
// This is our template that is being rendered.
namespace View\Example;
use BrightNucleus\Config\ConfigFactory;
use BrightNucleus\View\ViewBuilder;
use BrightNucleus\View\Location\FilesystemLocation;
// Fetch the Config from somewhere.
$config = ConfigFactory::create(__DIR__. '/config/views.php');
// Create a new instance of the ViewBuilder and add a location.
$viewBuilder = new ViewBuilder( $config );
$viewBuilder->addLocation(new FilesystemLocation(__DIR__ . '/views'));
// Create a new instance of a specific View.
$view = $viewBuilder->create('my-view');
// Render the view.
echo $view->render(['answer' => 42]);