Issue
In Laravel, there are different ways of using sections:
@yield('section1') // Filled in by child view
@section('section2')
// Default content, can be overwritten by child
// Different ways of closing the section
@endsection|stop|show|append
Who can tell me what the exact difference is between all of these?
Accoding to this, @stop and @endsection might be the same. (with one having been deprecated, but not anymore)
Solution
@endsection
and @stop
are the same and indicate the end of a section.
The section is not actually rendered on the page until you do @yield('sectionname')
In contrast, @show
is equivalent to
@stop
@yield('sectionname')
i.e. it stops and immediately renders the section at that part of the page.
@append
is basically equivalent to:
//FileA.blade.php
@section('sectionname')
... content
@stop
//FileB.blade.php
@extends('fileA')
@section('sectionname')
@parent
... more content after content
@stop
Here's some relevant source code:
protected function compileStop() {
return '<?php $__env->stopSection(); ?>';
}
protected function compileEndsection() {
return '<?php $__env->stopSection(); ?>'; //Same code
}
protected function compileShow() {
return '<?php echo $__env->yieldSection(); ?>';
}
Yield section just stops the current section and yields its contents.
Answered By - apokryfos
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.