buchin / slim-blade-view
Blade for Slim Framework 3 with Custom Directive
0.1.1
2016-03-11 02:32 UTC
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: 2024-11-15 19:34:42 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'; ?>"; });