Framework: Blade @push order with @extends and @include

Created on 16 Apr 2016  路  4Comments  路  Source: laravel/framework

(See also issue #12948)

After upgrading to Laravel 5.2.27, @push stack order is reversed when using @include into an extending view :

>>> a.blade.php
a
@stack('me')

>>> b.blade.php
@push('me') b @endpush('me')

>>> c.blade.php
@extends('a')
@include('b')
@push('me') c @endpush('me')

Compiling c.blade.php will produce a c b instead of a b c

As a reminder, issue #12948 fix @push with multiple @extends :

>>> a.blade.php
a
@stack('me')

>>> b.blade.php
@extends('a')
@push('me') b @endpush('me')

>>> c.blade.php
@extends('b')
@push('me') c @endpush('me')

Compiling c.blade.php will correctly produce a b c

This is a comment from @mark86092 on issue #12948 :

@include will increase renderCount, same as @extends does, renderCount determine the position of each @push block. The problem now is complicated. If fix, @push with @include is weird, if no fix, @push with @extends is weird.

Most helpful comment

@mark86092 I analyze a little bit how it works and I understand the difficulty. As you say this is complex.

Adding a test is a good idea, thanks for that. Now I can try to find a solution or at least an idea... ;)

All 4 comments

Yes, this has a bug fix, Please upgrade to the very latest version, and clear the view cache.

Sorry, but no, this is not fixed... read again, this is not the same issue.

I try with the dev-master (and 5.2.29) branch of laravel/framework, clear the view cache, and the problem is the same : @stack order is reversed with @push and @include into an extending view.

Please, take 5 minutes and try my examples and you will see.

When removing array_reverse from yieldPushContent (Illuminate/View/Factory.php) this will fix this issue but breaks issue #12948.

The difficulty here is to fix this issue without breaking the other one.

@sebastienheyd, it seems not an easy problem. The logic behind @include and @extends is complex, maybe fix it in 5.3 (?)

Anyway, I propose test for these kind of combining bugs #13181

@mark86092 I analyze a little bit how it works and I understand the difficulty. As you say this is complex.

Adding a test is a good idea, thanks for that. Now I can try to find a solution or at least an idea... ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Anahkiasen picture Anahkiasen  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments

iivanov2 picture iivanov2  路  3Comments

progmars picture progmars  路  3Comments