PHP code example of rudra / view
1. Go to this page and download the library: Download rudra/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/ */
rudra / view example snippets
use Rudra\View\ViewFacade as View;
echo View::view('layout', [
'content' => View::view('page', [
'foo' => 'foo',
'bar' => 'bar'
]),
]);
use Rudra\View\ViewFacade as View;
echo View::cache(['mainpage', '+1 day']) ?? View::render(['layout', 'mainpage'], [
'content' => View::cache(["page_{$slug}", '+1 day']) ?? View::view(['page', "page_{$slug}"], [
'foo' => 'foo',
'bar' => 'bar'
]),
]);
render('layout', [
'content' => view('page', [
'foo' => 'foo',
'bar' => 'bar'
]),
]);
data([
'content' => view('page', [
'foo' => 'foo',
'bar' => 'bar'
]),
]);
render('layout', data());
data([
'content' => cache(["page_{$slug}", '+1 day']) ?? view(['page', "page_{$slug}"], [
'foo' => 'foo',
'bar' => 'bar'
]),
]);
cache(['mainpage', '+1 day']) ?? render(['layout', 'mainpage'], data());
namespace App\Containers\Web\Factory;
use Rudra\View\View;
use Rudra\View\TwigView;
use Rudra\Container\Interfaces\FactoryInterface;
class TwigFactory implements FactoryInterface
{
public function create(): TwigView
{
$view = new TwigView();
$view->setup(
viewPath: dirname(dirname(__DIR__)) . '/Web/UI/tmpl',
prefix: '',
extension: 'twig'
);
return $view;
}
}
use Rudra\View\View;
use Rudra\View\TwigView;
use App\Containers\Web\Factory\TwigFactory;
return [
'contracts' => [
],
'services' => [
// View::class => function () {
// $view = new TwigView();
// $view->setup(
// viewPath: dirname(__DIR__) . '/Web/UI/tmpl',
// prefix: '',
// extension: 'twig'
// );
// return $view;
// }
// View::class => fn() => (new TwigFactory())->create(),
View::class => TwigFactory::class,
]
];