Laravel - 将变量传递给partial

时间:2017-05-23 14:52:39

标签: laravel-5.3

我在应用布局中使用相同的部分两次。我像这样传递变量:

<body>

  <div class="background-container">
    <img src="{{ asset('/img/cover_art.jpg') }}" alt="" />
  </div>

  @section('topBar')
    @include('customer.layouts.partials.top-bar')
  @show

  <div class="panel">

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

  <div class="container">

      @section('magazine-detail')
        @include('customer.layouts.partials.magazine-detail')
      @show
      <div class="show-for-medium">
        @section('carousel')
          @include('customer.layouts.partials.carousel', ['section' => 'footer-carousel'])
        @show
      </div>

  </div>

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

</body>

然后在部分我得到这样的变量:

<section class="carousel {{ $section }}">

问题是我得到了两个部分header-carousel的相同值。我该如何解决这个问题? 这是精简的html输出:

<nav class="side-nav">
</nav>
<section class="top-bar">
  ...
</section>

<section class="carousel header-carousel">
  ...
</section>
<section class="row magazine-detail">
    ...
</section>

<section class="carousel header-carousel">
  ...
</section>

0 个答案:

没有答案