Bird
0
0

How can you pass a variable named title with value 'Welcome' to a sub-view header using @include?

hard📝 Application Q15 of 15
Laravel - Views and Blade Templates
How can you pass a variable named title with value 'Welcome' to a sub-view header using @include?
A<code>@include('header')->with('title', 'Welcome')</code>
B<code>@include('header', ['title' => 'Welcome'])</code>
C<code>@include('header', title = 'Welcome')</code>
D<code>@include('header', {title: 'Welcome'})</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall passing data syntax in @include

    To pass data, use an associative array as the second argument: @include('view', ['key' => value]).
  2. Step 2: Check each option for correct syntax

    @include('header', ['title' => 'Welcome']) uses the correct array syntax. Options A, C, and D use invalid or unsupported syntax.
  3. Final Answer:

    @include('header', ['title' => 'Welcome']) -> Option B
  4. Quick Check:

    Pass data as array in second argument [OK]
Quick Trick: Pass variables as array in second argument of @include [OK]
Common Mistakes:
  • Using method chaining with @include
  • Passing variables without array brackets
  • Using object or JS-like syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes