buchin / slim-blade-view
Blade for Slim Framework 3 with Custom Directive
Installs: 18 566
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 7
pkg:composer/buchin/slim-blade-view
Requires
- illuminate/view: 5.*
- philo/laravel-blade: 3.*
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^5.0
- slim/slim: ^3.0
This package is auto-updated.
Last update: 2025-09-15 21:37:04 UTC
README
Usage
In index.php set up the blade container:
$container = $app->getContainer(); $blade = new \Slim\Views\Blade( '/path/to/views/folder', '/path/to/cache/folder' ); // [optional] insert custom directive here $container['blade'] = $blade;
Example code to render index.blade.php in route:
return $this->blade->render($response, 'index', $args);
Advanced: Custom directive:
$container = $app->getContainer(); $blade = new \Slim\Views\Blade( '/path/to/views/folder', '/path/to/cache/folder' ); // example directive here, usage: @helloWorld $blade->getRenderer()->getCompiler()->directive('helloWorld', function(){ return "<?php echo 'Hello World'; ?>"; }); $container['blade'] = $blade; $app->run();
If you like to build custom directive using $app:
$app->getContainer()['blade']->getRenderer()->getCompiler()->directive('helloWorld', function(){ return "<?php echo 'Hello My Second World'; ?>"; });