Beginner LevelLaravel
What is Blade Templating and how do custom directives work?
❓ Interview Prompt: Explain Blade template inheritance, layout views, components, control structures (@if, @foreach), and custom directives.
Blade is Laravel's simple yet powerful templating engine. Blade views compile to plain PHP code and are cached until modified.
Core Features:
•
Template Inheritance: Uses '@extends("layouts.app")' and '@section("content")' to build master layout hierarchies.
•
Control Structures: Offers concise directives like '@if', '@auth', '@guest', and '@forelse'.
•
Custom Directives: Created via 'Blade::directive("money", callback)' in Service Providers.
Code Implementation Example
php
<?php
// In AppServiceProvider::boot()
use IlluminateSupportFacadesBlade;
Blade::directive('currency', function ($expression) {
return "<?php echo '$' . number_format($expression, 2); ?>";
});💡Registering a custom Blade directive for currency formatting.
🎯 Interview Key Takeaway
Blade templates compile to plain PHP and offer clean layout inheritance and custom directive extensions.
#Blade#Templates#Directives#Beginner
Back to all Laravel Questions→