Files
slim-views-blade/README.md

67 lines
1.5 KiB
Markdown
Raw Permalink Normal View History

2021-10-13 21:57:32 -03:00
# Slim-Views-Blade
2017-01-11 11:02:42 +09:00
This is a Slim Framework view helper built on top of the Blade component.
You can use this component to create and render templates in your Slim Framework application.
## Install
Via [Composer](https://getcomposer.org/)
2017-01-11 11:06:18 +09:00
```bash
2021-10-13 21:57:32 -03:00
$ composer require provm/slim-views-blade
2017-01-11 11:02:42 +09:00
```
2021-10-13 21:57:32 -03:00
Requires Slim Framework 4 and PHP 7 or newer.
2017-01-11 11:02:42 +09:00
## Usage
2017-01-11 11:06:18 +09:00
```php
2017-01-11 11:02:42 +09:00
// Slim Settings
$config = [
'settings' => [
'displayErrorDetails' => true, // set to false in production
// Renderer settings
'renderer' => [
'blade_template_path' => 'path/to/views', // String or array of multiple paths
'blade_cache_path' => 'path/to/cache', // Mandatory by default, though could probably turn caching off for development
],
],
];
// Create Slim app
$app = new \Slim\App($config);
// Fetch DI Container
$container = $app->getContainer();
// Register Blade View helper
$container['view'] = function ($container) {
return new \Slim\Views\Blade(
$container['settings']['renderer']['blade_template_path'],
$container['settings']['renderer']['blade_cache_path']
);
};
// Define named route
$app->get('/hello/{name}/', function ($request, $response, $args) {
return $this->view->render($response, 'profile', [
'name' => $args['name'],
]);
})->setName('profile');
// Run app
$app->run();
```
## Testing
2017-01-11 11:06:18 +09:00
```bash
2017-01-11 11:02:42 +09:00
$ phpunit
```
## License
The MIT License (MIT). Please see [License File](LICENSE) for more information.