Leff Leff - 1 year ago 86
PHP Question

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

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">


@include('customer.layouts.partials.carousel', ['function' => 'drawer'])

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

So, as you can see I am using
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">
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 }}'

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

Answer Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download