PHP code example of bnf / pug-view

1. Go to this page and download the library: Download bnf/pug-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/ */

    

bnf / pug-view example snippets


use Bnf\PugView\PugRenderer;

ainer = $app->getContainer();

$settings = [
    'extension' => '.pug',
    'basedir' => 'templates/'
];

$container['view'] = function($c) {
	return new PugRenderer($settings);
};

/* PugRenderer is added as middleware to automatically inject the $response object. */
$app->add('view');

/* Add global template variables */
$app->add(function($request, $response, $next) {
    $this->view->set('title', 'default title');
    // Make the container accessible in the view, so that every object can be accessed in the template:
    // E.g: a(href=c.router.pathFor('named-route'))
    $this->view->set('c', $this);

    return $next($request, $response);
});

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->view->render('hello', $args);
});

$app->run();

//Construct the View
$settings = [
    'extension' => '.pug',
    'basedir' => 'templates/'
];
$phpView = new PugRenderer($settings);

//Render a Template
$response = $phpView->render('template', $yourData, new Response());