Laravel - Difference between @yield and @section?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Diving Deep into Laravel's Template System: @yield vs @section Body: From the Laravel docs (http://laravel.com/docs/5.0/templates), you can include 'sections' inside layouts using two methods. Let us examine them closely to understand their differences and best practices for using each. 1. @yield vs @section
<html>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>
The above code snippet showcases the usage of both @section and @yield. While they are similar, each has a specific purpose: - '@yield': It represents where content should be placed on the page. This is usually located within a parent layout file (such as 'app.blade.php') that will hold the actual content. The main difference between '@yield' and '@section' is that it accepts default content using '@yield('section', 'Default Content')'.
<html>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('content', 'Default Content')
        </div>
    </body>
</html>
The above code snippet shows how to pass default content for a particular section using '@yield'. - '@section': It represents a specific part of your layout where some content needs to be placed. This is mostly useful when you have a large amount of content and want to organize it in different sections or areas within the layout that can be accessed by child layouts/views.
<html>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('header')
            @yield('content')
            @yield('footer')
        </div>
    </body>
</html>
The above code snippet illustrates how you can use '@section' to create a complex layout with different content sections, each of which is filled by child layouts/views. Apart from these technical aspects, there are also some essential concepts to be aware of when using these directives: 1. The @parent Directive: When working with nested sections, you may need to reference the parent section's content. You can use '@parent' to display the content that was previously placed in that specific section within the parent layout. For example:
<html>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('header')
            @section('sidebar-inner', '@parent')
                The inner content for this specific part of the sidebar.
            @show
            @yield('content')
            @yield('footer')
        </div>
    </body>
</html>
2. Nesting Sections: You can also nest sections within other sections to create hierarchical layouts, ensuring the most relevant content is displayed in each section.
<html>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('header')
            @section('sidebar-inner', '@parent')
                The inner content for this specific part of the sidebar.
            @show
            @yield('content')
            @yield('footer')
        </div>
    </body>
</html>
In summary, '@yield' and '@section' play different roles within Laravel's template system. While '@yield' is used for displaying content in a particular area, '@section' allows you to create specific content sections that can be accessed by nested layouts or child views. As always, it's essential to keep your code organized and easy to maintain. Conclusion: In Laravel's template system, understanding the differences between '@yield' and '@section' is crucial for creating clean, organized, and efficient layouts. When used appropriately, these directives can significantly simplify the development process and provide a better user experience by structuring your site effectively.