ngangchill / blade
该包的最新版本(1.0.0)没有可用的许可证信息。
这是一个独立的laravel blade包,包含一些额外功能,例如部分视图和有用的指令。
1.0.0
2016-12-10 14:41 UTC
Requires
- php: >=5.5.9
- illuminate/view: ~5.2.0
This package is not auto-updated.
Last update: 2024-09-23 15:20:59 UTC
README
这是一个独立的laravel blade包,包含一些额外功能,如部分视图、有用的指令和扩展。感谢使用。
使用
$pathsToTemplates = __DIR__ . '/views';
$pathToCompiledTemplates = __DIR__ . '/compiled';
//fire laravel blade statically
Ngangchill\Blade\Blade::fire()->setPaths($pathsToTemplates, $pathToCompiledTemplates);
// or
$app = new Ngangchill\Blade\Blade();
$app->setPaths($pathsToTemplates, $pathToCompiledTemplates);
ALL DONE done... 现在让我们来玩玩laravel Blade 模板。现在您可以使用laravel bladetemplate文档中记录的所有Blade函数。
示例
$name = 'Skyfall';
echo View::make('index', ['name' => $name])->render();
// Add a location to the array of view locations.
View::addLocation($newPath);
// lets register a new directives
Blade::directive('hellow', function ($name) {
return "<?php echo 'Hellow <em>' . $name . '</em>'; ?>";
});
// For more info read laravel Blade Template Docs
注意:特殊情况 [如果您想使用 Illuminate\Support\Facades\Blade ]
如果您初始化blade类 Ngangchill\Blade\Blade::fire()->setPaths('viewPath', 'compiledPath'),则无需担心。但如果您使用use语句为Ngangchill\Blade\Blade类,那么您需要注意,为了避免出现不必要的错误,应给Ngangchill\Blade\Blade类设置别名或在Illuminate\Support\Facades\Blade前添加一个反斜杠''。以下是一个示例
要使用laravel blade facades,请按以下方式调用它
use Ngangchill\Blade\Blade;
//fire laravel blade
Blade::fire()->setPaths($pathsToTemplates, $pathToCompiledTemplates);
//Now call **Illuminate\Support\Facades\Blade** as \Blade::()....
\Blade::directive('datetime', function ($expression) {
return "<?php echo $expression->format('m/d/Y H:i'); ?>";
});
或
设置别名
use Ngangchill\Blade\Blade as ViewFactory;
//then
ViewFactory::fire()->setPaths(......);
Blade::directive('datetime', function ($expression) {
return "<?php echo $expression->format('m/d/Y H:i'); ?>";
});
否则可能会抛出不必要的错误。
在laravel.com上了解更多信息
额外功能
创建部分视图
我们使用@render('block-to-render')
指令来渲染通过相应的@block
指令提供的内容块。请注意,我们还可以提供默认值。
<div class="panel"> <div class="panel-heading"> <h3 class="panel-title">@render('title', 'Default Title')</h3> </div> <div class="panel-body"> @render('body', 'Default Body') </div> </div>
查看部分视图
部分视图从@partial('path.to.view')
指令开始,该指令接受部分视图要扩展的视图,并以@endpartial
指令结束。
@partial('partials.panel') @block('title', 'This is the panel title') @block('body') This is the panel body. @endblock @endpartial
部分内的块的行为与模板内的部分相同。它们捕获将被渲染到扩展视图中的数据片段。
特别感谢 crhayes
可用指令
@explode()
@implode()
@dd()
@dump()
@datetime()
@date()
@time()
@use()
@namespace()
@fa()