Limon Monte
Limon Monte

Reputation: 54389

Laravel 5 - potential bug in extended templates (@yield, @extends)

Just noticed strange behavior of extended views in Laravel 5. It seems like a bug in Laravel and I prepared simple code so you can easily reproduce it:

Controller:

$items = [
    ['id' => 1],
    ['id' => 2],
];

return view('list', [
    'items' => $items
]);

list.blade.php:

@foreach ($items as $item)
  @include('single-extended', $item)
@endforeach

single.blade.php:

<div>id: {{ $id }}</div>

@yield('block')

single-extended.blade.php:

@extends('single')

@section('block')
  <div>id in extended: {{ $id }}</div>
@endsection

Current output:

id: 1
id in extended: 1
id: 2
id in extended: 1

Expected output:

id: 1
id in extended: 1
id: 2
id in extended: 2

Is it a bug or I'm doing something wrong?

Upvotes: 1

Views: 338

Answers (1)

christophetd
christophetd

Reputation: 3874

Try using @overwrite instead of @endsection (which is by the way deprecated since Laravel 3 - you should use @stop in basic cases).

Upvotes: 1

Related Questions