A PHP Mustache class for render views on Slim 3 Framework.
Via Composer:
$ composer require andrewslince/slim3-mustache-view
<?php
$app = new \Slim\App([
// your application settings
]);
// get application container
$container = $app->getContainer();
// register view template engine and configurations
$container['renderer'] = function () {
return new \Slim\Views\Mustache([
// REQUIRED
'template' => [
// REQUIRED
'paths' => [
realpath('./templates')
],
// optional
'extension' => 'html',
// optional
'charset' => 'utf-8',
],
// put other mustache options here¹
]);
};
// use the render() method in your application routes
$app->get('/', function ($request, $response, $args) {
// render your view
return $this->renderer->render(
$response,
'index',
$args
);
});
$app->run();
NOTES:
¹ See other Mustache options here.
To running unit tests, executes the command below:
./vendor/bin/phpunit -c phpunit.xml.dist
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.