1. Go to this page and download the library: Download pug/slim 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/ */
pug / slim example snippets
use Slim\App;
use Slim\Pug\PugRenderer;
Slim settings
$app = PugRenderer::create(new App($slimOptions), './templates');
$app->get('/hello/{name}', function ($request, $response, $args) {
return $this->renderer->render($response, 'hello.pug', $args);
});
$app->run();
use Slim\Pug\PugRenderer;
e(null, './templates');
//Construct the View
$pugView = new PugRenderer('./path/to/templates', [
'option' => 'foobar',
]);
//Render a Template
$response = $pugView->render(new Response(), '/path/to/template.pug', $yourData);
// via the constructor
$templateVariables = [
'title' => 'Title',
];
$pugView = new PugRenderer('./path/to/templates', [], $templateVariables);
// or setter
$pugView->setAttributes($templateVariables);
// or individually
$pugView->addAttribute($key, $value);
$templateVariables = [
'title' => 'Title',
];
$pugView = new PhpRenderer('./path/to/templates', $templateVariables);
//...
$pugView->render($response, $template, [
'title' => 'My Title',
]);
// In the view above, the $title will be "My Title" and not "Title"