← Back to Course

Layouts and Sections (@yield, @extends)

Most pages on a site share the same overall structure — a header, a footer, and a navigation bar — with only the middle content changing. Blade's layout system avoids duplicating that shared markup across every view.

Defining a Layout

A layout is just a regular Blade view that defines the common page structure, with one or more placeholders marking where child views should insert their own content. These placeholders are declared using @yield.

Extending a Layout

A child view declares which layout it belongs to using @extends, then fills in the placeholder using @section. Laravel merges the two together at render time, producing a complete HTML page.

DirectiveUsed InPurpose
@yield('content')Layout fileMarks where a child view's content should appear
@extends('layouts.app')Child viewDeclares which layout the view builds on
@section('content') ... @endsectionChild viewProvides the actual content for a named placeholder
@yield('title', 'Default')Layout fileYields a section with a fallback default value

Benefits of This Approach

Layouts solve page-level structure well, but for smaller, reusable pieces of UI — like a button or an alert — Laravel offers something more flexible: Blade components and slots.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course