Laravel - 将数据从 master blade 传递到 partial 并不适用于所有视图

Laravel - passing data from master blade to partial doesn't work for all views

我正在尝试将数据从我的主人 blade 传递到部分,具体取决于它的打开位置。这是我师傅的一部分blade:

<div id="main-section">
      @section('topBar')
        @include('customer.layouts.partials.top-bar')
      @show

      @section('header')
        @include('customer.layouts.partials.header')
      @show

      @section('carousel')
        @include('customer.layouts.partials.carousel', ['function' => 'drawer'])
      @show
    </div>

    <div id="drawer">
      <div id="item-detail">
      </div>
      <div id="item-detail-carousel">
        @section('carousel')
          @include('customer.layouts.partials.carousel', ['function' => 'itemDetail'])
        @show
      </div>
    </div>

因此,如您所见,我在两个地方使用了 customer.layouts.partials.carousel。 我正在接收这样的部分数据:

      <div class="swiper-container {{ $function }}">
          <div class="swiper-wrapper">
            @foreach($issues as $issue)
              <div class="swiper-slide">
                <img
                  src="/imagecache/large/{{ $issue->first()->image  }}"
                  onclick="{{ $function }}(
                    '{{ $issue->first()->magazine->id }}',
                    '{{ $issue->first()->magazine->name }}',
                    '{{ $issue->first()->magazine->summary ?: '' }}',
                    '{{ $issue->first()->magazine->image ?: '' }}',
                    '{{ $issue->first()->image  }}'
                    )"
                  >
              </div>
            @endforeach
          </div>
        </div>

Div #drawer 首先隐藏,有 display:none,点击 main-section 滑块中的图像显示。然后 #drawermain-section 上滑动。但是当我检查 chrome 中的元素时,我发现在 main-sectiondrawer 部分中,传递的数据都是 drawer#drawer 没有像我想的那样得到数据 ['function' => 'drawer']。 我怎样才能做到这一点?

我认为您误解了 @section 指令的工作原理。

对于初学者,您不应该有多个同名的 @section 指令(可以把它想象成带有 HTML 的 ID - 应该只有一个同名)。此外,如果您不打算使用 @extend 扩展文件,那么使用 @section 根本没有多大意义。

如果您从 @include('...') 周围删除 @section 指令,那么它们应该可以正常工作。

希望对您有所帮助!