美文网首页
Blade 模板中 @show @stop 的使用

Blade 模板中 @show @stop 的使用

作者: 伍源辉 | 来源:发表于2017-01-06 13:43 被阅读322次

@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。

相关文章

网友评论

      本文标题:Blade 模板中 @show @stop 的使用

      本文链接:https://www.haomeiwen.com/subject/gegmvttx.html