PHP code example of codemonster-ru / view
1. Go to this page and download the library: Download codemonster-ru/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/ */
codemonster-ru / view example snippets
use Codemonster\View\View;
use Codemonster\View\Locator\DefaultLocator;
use Codemonster\View\Engines\PhpEngine; // package: codemonster-ru/view-php
$locator = new DefaultLocator([__DIR__ . '/resources/views']); // can be an array of paths
$engine = new PhpEngine($locator, 'php'); // default extension: php
$view = new View(['php' => $engine], 'php');
// Render template
echo $view->render('emails.welcome', ['user' => 'Vasya']);
// Looks for: resources/views/emails/welcome.php
// Access the locator of the default engine (added in v2.2.0)
$defaultLocator = $view->getLocator();
$defaultLocator->addPath(__DIR__ . '/vendor/package/views');
// Register namespaced view paths (added in v2.3.0)
$view->addNamespace('admin', __DIR__ . '/resources/views/admin');
echo $view->render('admin::dashboard', ['user' => 'Vasya']);