This is a Slim Framework view helper built on top of the Plates templating component. You can use this component to create and render templates in your Slim Framework application.
Via Composer
$ composer require kadevland/slim-plates-view
Requires Slim Framework 3 and PHP 5.5.0 or newer.
// Create Slim app
$app = new \Slim\App();
// Fetch DI Container
$container = $app->getContainer();
// Register Plates View helper
$container['view'] = function ($c) {
$view = new \Kadevland\Slim\Plates\View\PlatesView('path/to/templates','extention');
// Instantiate and add Slim specific extension
$basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/');
$view->addExtension(new \Kadevland\Slim-Plates-View\PlatesViewExtension($c['router'], $basePath));
return $view;
};
// Define named route
$app->get('/hello/{name}', function ($request, $response, $args) {
return $this->view->render($response, 'profile.html', [
'name' => $args['name']
]);
})->setName('profile');
// Run app
$app->run();
This component exposes a custom path_for()
function to your Plates templates. You can use this function to generate complete URLs to any Slim application named route. This is an example Plates template:
<h1>User List</h1>
<ul>
<li><a href="<?= $this->path_for('profile', { 'name': 'josh' }) ?>">Josh</a></li>
</ul>
This component propose a feature is_url()
function to your Plates templates. You can use this function to check if URL match witch Request URL/Path. This is an example Plates template:
<h1>Categories List</h1>
<ul>
---
$link=path_for('categorie', { 'slug': 'my-categorie' });
<li class="<?=$this->is_url($link)?'active':''?>"><a href="<?=$link?>">My categorie</a></li>
---
</ul>
phpunit
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.