【问题标题】:Laravel blade section and yield. yield does not work wellLaravel 叶片截面和产量。产量不好用
【发布时间】:2023-12-14 18:23:01
【问题描述】:

我是 Laravel Blade 的忠实拥趸。

我想拆分 index.blade.php。 当 morumoru.blade.php modal.blade.php 的内容在 index.html 上时,效果很好。

/view/camila/cabelo/index.blade.php

@yield('camila.cabelo.morumoru')

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
SAMPLE
</button>

@yield('camila.cabelo.blade')

/view/camila/cabelo/morumoru.blade.php

@section('morumoru.blade')

<ul>
    <li><a href="/star">INDEX</a></li>
    <li><a href="/star/sun">SUN</a></li>
    <li><a href="/star/moon">MOON</a></li>
</ul>

@endsection

/view/camila/cabelo/modal.blade.php

@section('modal')
<!-- Modal -->
  <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalCenterTitle">...</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          ...
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary">OK</button>
        </div>
      </div>
    </div>
  </div>


@endsection

【问题讨论】:

    标签: laravel laravel-blade


    【解决方案1】:

    使用@include('camila.cabelo.morumoru')@include('camila.cabelo.modal') 而不是@yield

    【讨论】:

    • 没有任何改变......
    【解决方案2】:

    使用 include 代替 yield,并从刀片文件中删除 @section 和 @endsection

    像这样的*包含 @include('camila.cabelo.morumoru') 底部包含这样的@include('camila.cabelo.modal')

    【讨论】: