terranc / blade
独立的 Laravel 视图模板版本 - blade
0.1.0
2017-02-04 05:29 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-29 02:18:37 UTC
README
在不完整 Laravel 框架的情况下使用 Laravel Blade 模板。(组件 & 插槽支持)
安装
composer require terranc/blade
使用
<?php $path = ['/view_path']; // your view file path, it's an array $cachePath = '/cache_path'; // compiled file path $compiler = new \terranc\Blade\Compilers\BladeCompiler($cachePath); // you can add a custom directive if you want $compiler->directive('datetime', function($timestamp) { return preg_replace('/(\(\d+\))/', '<?php echo date("Y-m-d H:i:s", $1); ?>', $timestamp); }); $engine = new \terranc\Blade\Engines\CompilerEngine($compiler); $finder = new \terranc\Blade\FileViewFinder($path); // if your view file extension is not php or blade.php, use this to add it $finder->addExtension('tpl'); // get an instance of factory $factory = new \terranc\Blade\Factory($engine, $finder); // render the template file and echo it echo $factory->make('hello', ['a' => 1, 'b' => 2])->render();
您可以使用此扩展几乎享受 blade 的所有功能。然而,请记住,一些独家功能已被移除。
您不能
- 在模板文件中使用
@inject
@can
@cannot
@lang
- 添加任何事件或中间件
文档:https://laravel.net.cn/docs/5.4/blade
感谢 Laravel 及其作者。这是一个伟大的项目。
对于 ThinkPHP
https://github.com/terranc/think-blade