drc4925 2016-10-26 17:22
浏览 37
已采纳

Laravel - 将数据从主刀片传递到部分不适用于所有视图

I am trying to pass data from my master blade to the partial depending where it is open. This is part of my master 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>

So, as you can see I am using customer.layouts.partials.carousel in two places. I am receiving data in my partial like this:

      <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 is hidden first, has display:none, and it is shown on click on an image in the slider in the main-section. And then #drawer gets slides over the main-section. But when I inspect the elements in the chrome I see that both in the main-section and in the drawer section, data that was passed is drawer. The #drawer didn't get data ['function' => 'drawer'] as I thought it would. How can I achieve that?

  • 写回答

1条回答 默认 最新

  • drrog9853 2016-10-26 18:26
    关注

    I think you're misunderstanding how the @section directive is meant to work.

    For starters, you shouldn't have multiple @section directives with the same name (think of it like ids with HTML - there should only be one with that name). Also, if your not going to be extending files with @extend there isn't much point in using @section at all.

    If you remove the @section directives from around your @include('...') then they should work fine.

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝