mejta / standalone-blade

此包已被弃用且不再维护。没有建议的替代包。

v5.6.1 2018-06-20 08:40 UTC

This package is auto-updated.

Last update: 2020-08-24 21:17:42 UTC


README

本项目提供Blade作为独立库,与5.6 Laravel Blade兼容。请参阅Blade文档:[https://laravel.net.cn/docs/5.6/blade](https://laravel.net.cn/docs/5.6/blade)

兼容性

  • PHP >= 7.1

安装

composer require mejta/standalone-blade

使用方法

use Mejta\StandaloneBlade;

$viewDirs = [
    __DIR__ . '/views',
];

$cacheDir = __DIR__ . '/cache';

$engine = new StandaloneBlade($viewDirs, $cacheDir);

// Define custom directives
$engine->directive('datetime', function($expression) {
    return "<?php echo ($expression)->format('m/d/Y H:i'); ?>";
});

// Define custom if statements
$engine->if('env', function($environment) {
    return app()->environment($environment);
});

// Share variables with all templates
$engine->share('key', 'value');

// Render template
echo $engine->render('page-template', [
    'title' => 'Page title',
    'content' => 'Some example page content',
]);