PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 2, 2022

[FIXED] Laravel Blade: @stop VS @show VS @endsection VS @append

 March 02, 2022     laravel, laravel-5, laravel-blade, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing