Skip to content

Conversation

@hossein-zare
Copy link
Contributor

@hossein-zare hossein-zare commented Oct 23, 2024

I submitted the same PR a few days ago, but it was closed with an unrelated response and wasn’t properly reviewed. I was advised by your colleagues to resubmit it and be clearer. my previous PR #53222

Description

Let's say we want to have a custom @extends directive:

// ▪ I have to repeat this everywhere @extends('templates.MY_TEMPLATE_NAME.layouts.app') // ▪ Custom Directive // Automatically detects the current template name and prepends it @template_extends('layouts.app') 

Currently, this is impossible without modifying files in the ./vendor directory. My changes would be lost if I upgraded Laravel.

Solution

$this->footer is a protected property in BladeCompiler::class which is used inside CompilesLayouts::compileExtends()

Default Behavior of the Blade::directive without the $bind param

// Inside AppServiceProvider::boot() Blade::directive('template_extends', function () { // ... // ❌ Fails // $this refers to AppServerProvider $this->footer[] = $echo; });

🟢 Setting the $bind param to true

We can create advanced directives now

// Inside AppServiceProvider::boot() Blade::directive('template_extends', function () { // ... // ✅ Works // $this refers to BladeCompiler $this->footer[] = $echo; }, true );
@taylorotwell taylorotwell merged commit 63fb79d into laravel:11.x Oct 24, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants