Challenge - 5 Problems
Blade Syntax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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
Attempts:
2 left
💡 Hint
Look at how Blade outputs variables and how the @if directive works.
✗ Incorrect
The variable $name is set to 'Alice'. The {{ $name }} outputs 'Alice'. The @if condition checks if length is greater than 3, which is true, so the paragraph is shown.
📝 Syntax
intermediate1:30remaining
Which option correctly escapes output in Blade?
In Blade templates, which syntax safely escapes HTML to prevent XSS attacks?
Attempts:
2 left
💡 Hint
Think about which syntax escapes HTML and which outputs raw HTML.
✗ Incorrect
The {{ }} syntax escapes HTML by default. The {!! !!} syntax outputs raw HTML without escaping. @{{ }} is used to show literal {{ }} in output. @php echo outputs raw without escaping.
🔧 Debug
advanced2: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
@endforAttempts:
2 left
💡 Hint
Check if all Blade directives are properly closed.
✗ Incorrect
The code uses @foreach but closes with @endfor, which is a mismatch causing a syntax error.
❓ state_output
advanced2: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>
Attempts:
2 left
💡 Hint
Remember how Blade components pass content via slots and how attributes are accessed.
✗ Incorrect
The component receives 'error' as $type and the inner HTML as $slot, rendering them inside the div with correct classes and content.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Think about which directive is for including views with data.
✗ Incorrect
@include is used to insert a child view and pass data as an array. @component is for components, @yield is for sections, and @extends is for layout inheritance.