Blade 模板中 @show @stop 的使用

@show @stop 的区别

首先,@endsection 在 4.0 版本中已经移除,虽然向下兼容,但是不建议使用 。

case 5:

{{-- layout/master.blade.php --}}
@section('title')
    默认标题
@show

{{-- test.blade.php --}}
@extends('layout.master')
@section('title')
    新的标题
@show

新的标题 新的标题

case 6:

{{-- layout/master.blade.php --}}
@section('title')
    默认标题
@show

{{-- test.blade.php --}}
@extends('layout.master')
@section('title')
    新的标题
@stop

新的标题

case 7:

{{-- layout/master.blade.php --}}
@section('title')
    默认标题
@stop

{{-- test.blade.php --}}
@extends('layout.master')
@section('title')
    新的标题
@show

新的标题

case 8:

{{-- layout/master.blade.php --}}
@section('title')
    默认标题
@stop

{{-- test.blade.php --}}
@extends('layout.master')
@section('title')
@parent
    新的标题
@stop

(null)


结论

  • @show 指的是执行到此处时将该 section 中的内容输出到页面。
  • @stop 只是进行内容解析,并且不再处理当前模板中后续对该 section 的处理。
  • 首次定义某个 section 的时候,应该用 @show,而在替换它或者扩展它的时候,应该用 @stop。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容