This is a renderer for rendering PHP view scripts into a PSR-7 Response object. It works well with Slim Framework 3.
use Slim\Views\PhpRenderer;
include "vendor/autoload.php";
$app = new Slim\App();
$container = $app->getContainer();
$container['renderer'] = new PhpRenderer("./templates");
$app->get('/hello/{name}', function ($request, $response, $args) {
return $this->renderer->render($response, "/hello.php", $args);
});
$app->run();
//Construct the View
$phpView = new PhpRenderer("./path/to/templates");
//Render a Template
$response = $phpView->render(new Response(), "/path/to/template.php", $yourData);
\RuntimeException
- if template does not exist
\InvalidArgumentException
- if $data contains 'template'