Laravel Blade 模板引擎的 `@component` 指令
参考链接:https://laravel.com/docs/5.4/blade#components-and-slots
Laravel 5.4 为 Blade 模板引擎引入了 @component
指令,它在一定程度上代替了 @include
/ @includeIf
指令的作用,能更加清楚地表示要引入的是组件。
下面举例子。先定义一个 Alert 组件。
<!-- /resources/views/alert.blade.php -->
<div class="alert alert-danger">
<div class="alert-title">{{ $title }}</div>
{{ $slot }}
</div>
引入组件
@component('alert')
@slot('title')
Forbidden
@endslot
You are not allowed to access this resource!
@endcomponent
在组件中,$slot
是一个特殊的变量,它表示传递给组件的内容。引入组件时,除 @slot
指令之外的其余部分都被当做 $slot
的值、最终插入到定义组件时 {{ $slot }}
所在的位置上。
@slot
指令用来指定组件中命名槽变量,在这里指 title
——相对于组件默认支持的变量 slot
而言,它是用户自己命名的,所以被称为命名槽变量。
點擊查看更多內容
3人點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦