【问题标题】:Laravel - passing data from master blade to partial doesn't work for all viewsLaravel - 将数据从主刀片传递到部分不适用于所有视图
【发布时间】:2017-03-09 04:30:04
【问题描述】:

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

<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' =&gt; 'drawer']。 我怎样才能做到这一点?

【问题讨论】:

    标签: php laravel-5.3 laravel-blade


    【解决方案1】:

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

    对于初学者,您不应该有多个具有相同名称的 @section 指令(将其想象为带有 HTML 的 id - 应该只有一个具有该名称)。此外,如果您不打算使用@extend 扩展文件,那么使用@section 根本没有什么意义。

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

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2017-09-03
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      • 2019-04-13
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多