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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化