adelynx/blade

Laravel 8.* 之外使用的 Laravel Blade 模板引擎的独立版本

v2.0 2021-01-20 13:52 UTC

This package is auto-updated.

Last update: 2024-09-05 12:09:06 UTC


README

用于 Laravel 5.7 之外的 Laravel Blade 模板引擎的独立版本。

安装

您可以通过在终端或控制台中输入以下命令来使用 Composer 安装此包:

composer require adelynx/blade

用法

通过传入包含您的视图文件的文件夹(s)和一个缓存文件夹来创建 Blade 实例。通过调用 make 方法来渲染模板。有关 Blade 模板引擎的更多信息,请参阅 https://laravel.net.cn/docs/5.7/blade

<?php

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require 'vendor/autoload.php';

use Adelynx\Blade\Blade;

$blade = new Blade('views', 'cache');

echo $blade->make('homepage', ['name' => 'John Doe']);

现在您可以通过调用 compiler() 函数轻松创建指令。

$blade->compiler()->directive('datetime', function ($expression) {
    return "<?php echo with({$expression})->format('F d, Y g:i a'); ?>";
});

{{-- In your Blade Template --}}
<?php $dateObj = new DateTime('2018-01-01 23:59:59') ?>
@datetime($dateObj)

Blade 实例将所有方法传递给内部视图工厂。因此,existsfilesharecomposercreator 等方法也都可以使用。有关更多信息,请参阅 原始文档