- Laravel Version: v8.41.0
- PHP Version: 8.0.5
- Sail Version: v1.5.1
Description:
I have an a.blade.php view that, in body, contains a @yield directive like this
@yield('post_body_scripts')
Then, the view is included in another one, b.blade.php that holds data for the post_body_scripts section
@extends('partials.layouts.app')
...
@include('c', ['foo' => 'bar'])
@section('post_body_scripts')
<script src="{{ asset('js/b.js') }}"></script>
@endsection
The included c view contains another part of the post_body_scripts section
@section('post_body_scripts')
@parent
<script src="https://cdn/ajsfile.js"></script>
@endsection
The @parent directive correctly works, but an hashtag starting placeholder is shown when the render of the view starts
<?php $__env->startSection('post_body_scripts'); ?>
##parent-placeholder-1a5ac98c3addb84257eb2d5b7ffee8f1cbf3b352##
<script src="https://cdn/ajsfile.js"></script>
<?php $__env->stopSection(); ?><?php /**PATH /var/www/html/resources/views/c.blade.php ENDPATH**/ ?>
Steps To Reproduce:
- Create a base view that contains a @yield directive;
- Create a view that extends the previous one and uses a @section directive for the previous yield;
- Include, in the view created at point 2, another sub view;
- In the view included at point 3, use a @section directive that starts with @parent for the declared yield.
Update
As notified to me in comments I tried using @stack directive but problem is still here.
a.blade.php
@stack('post_body_scripts')
b.blade.php
@push('post_body_scripts')
....
@endpush
c.blade.php
@push('post_body_scripts')
@parent
....
@endpush
My Answer:
'bar'])_..._@section('post_body_scripts')_ _@endsection__However, when I render the b.blade.php view, the @yield directive in a.blade.php is not replaced with the content from b.blade.php. Instead, it remains as is_@yield('post_body_scripts')__.How can I make sure that the content from b.blade.php is rendered in the @yield directive of a.blade.php?
Rate this post
5 of 5 based on 2879 votesComments