esdlabs / string-blade-compiler
从字符串渲染 Blade 模板
v2.0.0
2015-01-24 00:55 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-18 06:46:11 UTC
README
从字符串值渲染 Blade 模板。
这是从 https://github.com/Flynsarmy/laravel-db-blade-compiler 分支而来,它使用 Elequent 模型传递模板。
我对它进行了重构,允许使用所需的字段通用的数组生成并返回从 blade 语法模板编译的视图。
版本
此版本 1 是针对 Laravel 4.2,版本 2 是针对 Laravel 5。
安装
将存储库添加到 composer.json
"repositories": [
{
"name": "wpb/string-blade-compiler",
"url": "https://github.com/TerrePorter/StringBladeCompiler.git",
"type": "git"
}
],
将包添加到 composer.json
"require": {
"laravel/framework": "4.2.*",
"wpb/string-blade-compiler": "1.*@dev"
},
将 ServiceProvider 添加到 app/config/app.php 中的 providers 数组
'Wpb\StringBladeCompiler\StringBladeCompilerServiceProvider',
不需要将 Facade 添加到与 ServiceProvider 相同的文件中的 aliases 数组,这将在 ServiceProvider 中自动包含。
使用方法
此包提供了一个与 View 语法相同的 StringView 门面,但接受一个 Array 或 Array Object 实例而不是视图路径。
return StringView::make( array( // this actual blade template 'template' => '{{ $token1 }}', // this is the cache file key, converted to md5 'cache_key' => 'my_unique_cache_key', // timestamp for when the template was last updated, 0 is always recompile 'updated_at' => 1391973007 ), array( 'token1'=> 'token 1 value' ) );
还允许 Blade::extend,例如
// allows for @continue and @break in foreach in blade templates Blade::extend(function($value) { return preg_replace('/(\s*)@(break|continue)(\s*)/', '$1<?php $2; ?>$3', $value); });
许可证
string-blade-compiler 是开源软件,许可协议为 MIT 协议