1. Go to this page and download the library: Download projek-xyz/slim-plates 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/ */
projek-xyz / slim-plates example snippets
// Create Slim app
$app = new \Slim\App();
// Fetch DI Container
$container = $app->getContainer();
// Register Plates View helper:
// Option 1, using PlatesProvider
$container->register(new \Projek\Slim\PlatesProvider);
// Option 2, using Closure
$container['view'] = function ($c) {
$view = new \Projek\Slim\Plates([
// Path to view directory (default: null)
'directory' => 'path/to/views',
// Path to asset directory (default: null)
'assetPath' => 'path/to/static/assets',
// Template extension (default: 'php')
'fileExtension' => 'tpl',
// Template extension (default: false) see: http://platesphp.com/extensions/asset/
'timestampInFilename' => false,
]);
// Set \Psr\Http\Message\ResponseInterface object
// Or you can optionaly pass `$c->get('response')` in `__construct` second parameter
$view->setResponse($c->get('response'));
// Instantiate and add Slim specific extension
$view->loadExtension(new Projek\Slim\PlatesExtension(
$c->get('router'),
$c->get('request')->getUri()
));
return $view;
};
// Define named route
$app->get('/hello/{name}', function ($request, $response, $args) {
return $this->view->render('profile', [
'name' => $args['name']
]);
})->setName('profile');
// Run app
$app->run();