xiaoler / blade
此包已被弃用,不再维护。未建议替代包。
独立的 Laravel 视图模板 - blade
5.4.3
2017-08-23 01:10 UTC
Requires
- php: >=5.4.0
README
这是一个从 Laravel 中提取出来的视图模板引擎。它是独立的,不依赖于 Laravel 的容器或其他任何东西。
安装
使用 Composer,你只需要运行
composer require xiaoler/blade
如果你还没有使用 composer,你应该将文件夹 src
中的所有文件添加到你的项目文件夹中,然后在你的代码中 require
它们。
使用方法
<?php require '../src/Autoloader.php'; Xiaoler\Blade\Autoloader::register(); use Xiaoler\Blade\FileViewFinder; use Xiaoler\Blade\Factory; use Xiaoler\Blade\Compilers\BladeCompiler; use Xiaoler\Blade\Engines\CompilerEngine; use Xiaoler\Blade\Filesystem; use Xiaoler\Blade\Engines\EngineResolver; $path = ['/view_path']; // your view file path, it's an array $cachePath = '/cache_path'; // compiled file path $file = new Filesystem; $compiler = new BladeCompiler($file, $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); }); $resolver = new EngineResolver; $resolver->register('blade', function () use ($compiler) { return new CompilerEngine($compiler); }); // get an instance of factory $factory = new Factory($resolver, new FileViewFinder($file, $path)); // if your view file extension is not php or blade.php, use this to add it $factory->addExtension('tpl', 'blade'); // 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 和它的作者。这是一个伟大的项目。