Blade is Laravel's templating engine with clean syntax.
Directives
@extends,@section,@yield� layout inheritance@foreach,@forelse� loops@if,@elseif,@else� conditionals
Blade is Laravel's templating engine with clean syntax.
@extends, @section, @yield � layout inheritance@foreach, @forelse � loops@if, @elseif, @else � conditionals@extends("layouts.app") @section("content") <h1>{{ $title }}</h1> @foreach($posts as $post) <div>{{ $post->title }}</div> @endforeach @if($posts->isEmpty()) <p>No posts found.</p> @endif @endsection
<!-- resources/views/posts/index.blade.php --> @extends("layouts.app") @section("content") @foreach ($posts as $post) <article> <h2>{{ $post->title }}</h2> <p>{{ $post->excerpt }}</p> @if ($post->image) <img src="{{ $post->image }}" alt="..."> @else <p>No image</p> @endif <small>{{ $post->created_at->diffForHumans() }}</small> @empty <p>No posts yet.</p> @endforelse @endsection
Create a Blade layout with header, content, and footer sections.
@extends("layouts.app")
@section("content")
<h1>{{ $title }}</h1>
@endsection
What does @yield do?
@yield defines where a section content should be placed.
Blade provides cleaner syntax, template inheritance, XSS protection via {{ }}, and compiles to PHP for caching.