Bird
0
0

How should you write the child view?

hard📝 Application Q15 of 15
Laravel - Views and Blade Templates
You have a base layout with multiple @yield placeholders: title, header, and content. You want to create a child view that fills only content and uses a default title and header from the layout. How should you write the child view?
A@extends('layouts.base') @yield('title') @yield('header') @section('content') <p>Page content here</p> @endsection
B@extends('layouts.base') @section('content') <p>Page content here</p> @endsection
C@extends('layouts.base') @section('title', 'Default Title') @section('header', 'Default Header') @section('content') <p>Page content here</p> @endsection
D@extends('layouts.base') @include('title') @include('header') @section('content') <p>Page content here</p> @endsection
Step-by-Step Solution
Solution:
  1. Step 1: Understand default content in layout

    If the base layout provides default content for title and header, you don't need to override those sections in the child view.
  2. Step 2: Write child view with only needed sections

    Only define the content section in the child view to fill that placeholder, leaving others to default.
  3. Final Answer:

    Child view extends layout and defines only content section -> Option B
  4. Quick Check:

    Define only needed sections; others use layout defaults [OK]
Quick Trick: Only override sections you want to change in child views [OK]
Common Mistakes:
  • Overriding sections unnecessarily
  • Using @yield inside child views
  • Trying to include sections with @include

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes