0
0
Laravelframework~20 mins

Blade template syntax in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Blade Syntax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will this Blade template output?
Given the following Blade template code, what will be rendered in the browser?
Laravel
@php
  $name = 'Alice';
@endphp

<h1>Hello, {{ $name }}!</h1>
@if(strlen($name) > 3)
  <p>Name is longer than 3 characters.</p>
@endif
A<h1>Hello, !</h1><p>Name is longer than 3 characters.</p>
B<h1>Hello, Alice!</h1>
C<h1>Hello, Alice!</h1><p>Name is longer than 3 characters.</p>
DSyntax error due to missing @endif
Attempts:
2 left
💡 Hint
Look at how Blade outputs variables and how the @if directive works.
📝 Syntax
intermediate
1:30remaining
Which option correctly escapes output in Blade?
In Blade templates, which syntax safely escapes HTML to prevent XSS attacks?
A{{ $userInput }}
B{!! $userInput !!}
C@{{ $userInput }}
D@php echo $userInput; @endphp
Attempts:
2 left
💡 Hint
Think about which syntax escapes HTML and which outputs raw HTML.
🔧 Debug
advanced
2:00remaining
What error does this Blade code cause?
Consider this Blade snippet. What error will it produce when rendered?
Laravel
@foreach($items as $item)
  <li>{{ $item }}</li>
@endforeach
@endfor
ASyntax error: Missing closing brace in {{ $item }}
BSyntax error: Unexpected @endfor without matching @for
CRuntime error: Undefined variable $items
DNo error, renders list items
Attempts:
2 left
💡 Hint
Check if all Blade directives are properly closed.
state_output
advanced
2:30remaining
What is the output of this Blade component with slots?
Given this Blade component usage, what will be rendered?
Laravel
<x-alert type="error">
  <strong>Error!</strong> Something went wrong.
</x-alert>

// Component blade:
// <div class="alert alert-{{ $type }}">
//   {{ $slot }}
// </div>
A
&lt;div class="alert alert-error"&gt;
  &amp;lt;strong&amp;gt;Error!&amp;lt;/strong&amp;gt; Something went wrong.
&lt;/div&gt;
B
&lt;div class="alert alert-"&gt;
  &lt;strong&gt;Error!&lt;/strong&gt; Something went wrong.
&lt;/div&gt;
CRuntime error: Undefined variable $slot
D
&lt;div class="alert alert-error"&gt;
  &lt;strong&gt;Error!&lt;/strong&gt; Something went wrong.
&lt;/div&gt;
Attempts:
2 left
💡 Hint
Remember how Blade components pass content via slots and how attributes are accessed.
🧠 Conceptual
expert
2:00remaining
Which Blade directive is used to include a child view and pass data?
You want to include a child Blade view named 'profile' and pass a variable $user to it. Which directive and syntax is correct?
A@include('profile', ['user' => $user])
B@component('profile', ['user' => $user]) @endcomponent
C@yield('profile', ['user' => $user])
D@extends('profile', ['user' => $user])
Attempts:
2 left
💡 Hint
Think about which directive is for including views with data.