Laravel Blade 模板 @section/endsection 与 @section/show, @yield 的区别

时间:2023-03-09 23:08:35
Laravel Blade 模板 @section/endsection 与 @section/show, @yield 的区别

base layout 中需要使用

@section("section_name")
区块链是什么?
@show

继承的 blade 中需要使用

@section("section_name")
区块链的定义
@endsection

其会覆盖父模板中的内容。

如果需要基于原 layout section 附加内容

@section("section_name")
@parent
<p>区块链是xxx</p>
@endsection

@yield 类似于 @section/show 的用法,但是其继承者不能使用 @parent。