Interview question
How does Laravel's Blade templating engine work? Laravel का Blade templating engine कैसे काम करता है?
Answer
Blade is Laravel's templating engine that compiles templates into plain PHP code, which is then cached for performance until the source file changes.
{{-- resources/views/welcome.blade.php --}}
@extends('layouts.app')
@section('content')
<h1>Hello, {{ $name }}</h1>
@if ($user->isAdmin())
<p>Welcome, admin!</p>
@endif
@foreach ($posts as $post)
<p>{{ $post->title }}</p>
@endforeach
@endsection| Directive | Purpose |
|---|---|
| {{ }} | Echo, auto-escaped for XSS safety |
| {!! !!} | Echo raw, unescaped HTML |
| @extends / @section | Template inheritance |
Blade Laravel का templating engine है जो templates को plain PHP code में compile करता है और performance के लिए cache करता है।
@extends('layouts.app')
@section('content')
<h1>Hello, {{ $name }}</h1>
@foreach ($posts as $post)
<p>{{ $post->title }}</p>
@endforeach
@endsectionWas this answer clear?