Reputation: 757
I have a sample view:
File: hello.blade.php
//includes the basic html enclosed tags
<p>Hello world<p>
@yield('content')
File: tester.blade.php
@extends('hello')
@section('content')
<p>this is a test<p>
@yield('contents')
@endsection
File: content.blade.php
@extends('tester.blade.php')
@section('contents')
<p>any code will do<p>
@endsection
now my problem is whenever it only renders
Hello world
this is a test
is there any workaround this? or blade engine does not support nested yields? anyhelp will be greatly appreciated
Upvotes: 2
Views: 1739
Reputation: 2644
I've tested it but doesn't do what we expect.
But there is one solution that I still use when I'm facing to such situation. I use @parent
blade directive like this
File: hello.blade.php
{{-- includes the basic html enclosed tags --}}
<p>Hello world<p>
@yield('content')
File: tester.blade.php
@extends('hello')
@section('content')
<p>this is a test<p>
@yield('contents')
@endsection
File: content.blade.php
@extends('tester.blade.php')
@section('contents')
@parent
<p>any code will do<p>
@endsection
Upvotes: 0
Reputation: 5262
I have not tested but you could try change content.blade.php
to
@extends('tester')
and make sure you use
return view('content');
However @include
inside @section
works. or using @parent
in content.blade.php
@extends('tester')
@section('content')
@parent
<p>any code will do</p>
@endsection
@parent
will cause Blade to append parent view content with current view rather than overwrite whole section.
Upvotes: 1