Laravel 的 Blade 模板引擎简介Blade 是 Laravel 提供的一个简单而又强大的模板引擎。和其他流行的 PHP 模板引擎不同,Blade 并不限制你在视图中使用原生 PHP 代码。所有 Blade 视图文件都将被编译成原生的 PHP 代码并缓存起来,除非它被修改,否则不会重新编译,这就意味着 Blade 基本上不会给你的应用增加任何负...
Blade & JavaScript 框架# 由于很多 JavaScript 框架都使用花括号来表明所提供的表达式,所以你可以使用@符号来告知 Blade 渲染引擎你需要保留这个表达式原始形态,例如: LaravelHello,@{{name}}. 在这个例子里,@符号最终会被 Blade 引擎剔除,并且{{ name }}表达式会被原样的保留下来,这样就允许你的 JavaScript 框架...
在这里我们指定的是 Blade.test 这个模板,并给 view() 方法的第二个参数通过数组的方式传递我们定义好的数据。 接下来在 resources/views 目录下,我们再创建一个 Blade 目录,然后在这个目录下面新建一个 test.blade.php 文件。这个文件,就是一个 Balade 的模板文件,在 Laravel 中,所有的模板文件都要放在 resourc...
尽管子视图会自动继承父视图中的所有数据变量,你也可以直接传递一个数组变量来添加额外的变量到子视图(在 Blade 视图中避免使用DIR和FILE常量,因为它们会解析为视图缓存所在的位置): @include('view.name', ['some' => 'data']) 你可以使用 Blade 的 @each 指令来在一行中合并引入多个视图: @each('view.nam...
定义子页面的时候,可以使用 Blade 的 @extends 指令来指定子页面所继承的布局,继承一个 Blade 布局的视图可以使用 @section 指令注入内容到布局定义的内容片段中,记住,如上面例子所示,这些片段的内容将会显示在布局中使用 @yield 的地方: <!-- 存放在 resources/views/child.blade.php --> @extends('layouts.ap...
Even though the included view will inherit all data available in the parent view, you may also pass an array of extra data to the included view: @include('view.name', ['some'=>'data']) You should avoid using the__DIR__and__FILE__constants in your Blade views, since they will refe...
Supercharged Blade components This package provides an easy way to render custom HTML components in your Blade views. Here's an example. Instead of this My view@include('myAlert', ['type'=>'error','message'=>$message]) you can write...
@includeIf('view.name',['some'=>'data']) You should avoid using the__DIR__and__FILE__constants in your Blade views, since they will refer to the location of the cached, compiled view. Rendering Views For Collections You may combine loops and includes into one line with Blade's@each...
Inertia Table: The Ultimate Table for Inertia.js with built-in Query Builder. Laravel Blade On Demand: Laravel package to compile Blade templates in memory. Laravel Cross Eloquent Search: Laravel package to search through multiple Eloquent models. Laravel Eloquent Scope as Select: Stop duplicating ...
为了方便,Blade 还提供了@unless指令: @unless(Auth::check())You are not signedin.@endless 除了讨论过的条件判断指令,Blade 还提供了@isset和@empty指令,都与在原生 PHP 里的对应功能相同: @isset($recodes)// $recodes is defined and is not null ...@endisset@empty($recodes)// $recodes is "emp...