Core Laravel · 8 min read · Intermediate
Blade Templates, Layouts & Reusable Components
Build clean, XSS-safe server-rendered UIs using Blade directives, slots, and anonymous components.
What you'll learn
- Escape output safely with `{{ }}` and avoid raw `{!! !!}` on untrusted input
- Compose reusable layouts with `<x-layout>` components and `$slot`
- Use `@forelse`, `@csrf`, and `@error` directives cleanly in views
Overview
Build clean, XSS-safe server-rendered UIs using Blade directives, slots, and anonymous components.
Code Example
<!-- resources/views/components/alert.blade.php -->
@props(['type' => 'info'])
<div {{ $attributes->merge(['class' => 'rounded-xl p-4 border']) }}>
{{ $slot }}
</div>
<!-- Usage in a Blade view -->
<x-alert type="success">
Welcome back, {{ $user->name }}.
</x-alert>
Key Takeaways
- Escape output safely with
{{ }}and avoid raw{!! !!}on untrusted input - Compose reusable layouts with
<x-layout>components and$slot - Use
@forelse,@csrf, and@errordirectives cleanly in views
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why should user-submitted text always be rendered with `{{ $text }}` instead of `{!! $text !!}` in Blade?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.