【问题标题】:Can blade yield to a section in the same file?刀片可以屈服于同一文件中的一个部分吗?
【发布时间】:2014-03-12 11:25:37
【问题描述】:

我有文件 master.blade.php,其中包含 @yield('mainsection')。然后我有另一个文件,其中:

@extends('layouts.master')

@section('mainection')
    test1
    @yield('othersection')
@stop

@section('othersection')
    test2
@stop

我可以看到test1,但看不到test2 - 我从中得出结论,刀片不允许您屈服于同一文件中定义的部分。有没有办法解决这个问题?还是我必须在这两个文件之间添加第三个文件,以包含主要部分并屈服于其他部分?

【问题讨论】:

    标签: laravel-4 templating blade


    【解决方案1】:

    可以显示,但@section必须写在@yield之前

    @extends('layouts.master')
    
    @section('othersection')
      test2
    @stop
    
    @section('mainection')
      test1
      @yield('othersection')
    @stop
    

    【讨论】:

      猜你喜欢
      • 2017-05-25
      • 2015-06-01
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多