Blade: template expansion in several subzones

I use Blade to include multiple subviews in one set of tabs in a blade application. All subtasks have the same general structure (sidebar and main section). Because of this, I created a template, and each subtask extends the template. Here is the structure:

Main.blade.php

<div id="tabs">
  <ul>
    @foreach($views as $view)
    <li><a href="#{{$view}}">{{$view}}</a></li>
    @endforeach
  </ul>
  @foreach($views as $view)
  <div id="{{$view}}">
    @include($view)
  </div>
  @endforeach
</div>

template.blade.php

{{-- formatting stuff --}}
  @yield('content 1')
{{-- more formatting stuff --}}
  @yield('content-2')
{{-- more formatting stuff --}}

tab -. * Blade.php

@extends('template')

@section('content-1')
This is tab [whatever number]
@stop

@section('content-2')
Lorem Ipsum
@stop

The obvious problem is that since each subtask extends the same template, @yield('content')there are 3 times, and all 3 included subtasks have their own @section('content'). What seems to be happening is that the first implementation of the sub-representation of the content section is placed in all 3 outputs.

. , , , THEN, . ?

tab - *. blade.php , . , , . , "" .

, , . @include (, ..), , . , , , , , .

+4
2

, , , . template.blade.php :

{{-- formatting stuff --}}
  @yield(isset($tab) ? "content-1-$tab" : 'content-1')
{{-- more formatting stuff --}}
  @yield(isset($tab) ? "content-2-$tab" : 'content-2')
{{-- more formatting stuff --}}

, main.blade.php, @include('view', ['tab'=>$view]). , content-1 content-2 , . , , , .

+3

@overwrite @stop

:

@extends('template')

@section('content-1')
     Stuff goes here...
@overwrite

@section('content-2')
     More stuff goes here...
@overwrite

: https://github.com/laravel/framework/issues/1058#issuecomment-17194530

+3

All Articles