kadevland / slim-plates-view
Slim Framework 3 view helper built on top of the Plates templating component
Requires
- php: >=5.5.0
- league/plates: ^3.1
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^4.8.0
This package is not auto-updated.
Last update: 2019-11-06 21:25:46 UTC
README
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.
Install
Via Composer
$ composer require kadevland/slim-plates-view
Requires Slim Framework 3 and PHP 5.5.0 or newer.
Usage
// 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();
Custom template functions
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>
Testing
phpunit
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.