buchin/slim-blade-view

带有自定义指令的Slim Framework 3的Blade模板

0.1.1 2016-03-11 02:32 UTC

This package is auto-updated.

Last update: 2024-09-15 19:09:34 UTC


README

用法

在index.php中设置blade容器

$container = $app->getContainer();
$blade = new \Slim\Views\Blade(
    '/path/to/views/folder',
    '/path/to/cache/folder'
);

// [optional] insert custom directive here

$container['blade'] = $blade;

在路由中渲染index.blade.php的示例代码

return $this->blade->render($response, 'index', $args);

高级:自定义指令

$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();

如果你喜欢使用$app构建自定义指令

$app->getContainer()['blade']->getRenderer()->getCompiler()->directive('helloWorld', function(){

    return "<?php echo 'Hello My Second World'; ?>";
});