Bird
0
0

Why does Blade use both @section and @yield directives instead of just one?

hard📝 Conceptual Q10 of 15
Laravel - Views and Blade Templates
Why does Blade use both @section and @yield directives instead of just one?
A@section includes partials; @yield extends layouts.
B@section defines content blocks; @yield displays them in layouts.
C@section is for PHP code; @yield is for HTML code.
DThey are interchangeable and used for the same purpose.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the roles of @section and @yield

    @section defines content in child views; @yield marks where that content appears in the layout.
  2. Step 2: Clarify why both are needed

    They separate content definition from content placement, enabling flexible template inheritance.
  3. Final Answer:

    @section defines content blocks; @yield displays them in layouts. -> Option B
  4. Quick Check:

    @section = define, @yield = display [OK]
Quick Trick: Use @section to define, @yield to display content [OK]
Common Mistakes:
  • Thinking @section and @yield do the same thing
  • Confusing their roles with PHP vs HTML
  • Mixing up @include and @extends

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes