Blade - How to @push content to start of a @stack?
In blade, you can create stacks. See the following for more information:
https://laravel.com/docs/5.2/blade#stacks
However the above link only shows how to push elements to the end of the stack. I want to append an element to the start of the stack. How can I do this?
e.g.
@push('foo')pizza @endpush
@push('foo')like @endpush
@push('foo')I @endpush
@stack('foo')
outputs:
pizza like I
I want it to output:
I like pizza
This is something that I wouldn't recommend doing because this is the way Laravel is built.
But, if for any reason, you need it so much and you don't see any other way to accomplish it, You can tweak the framework itself.
The file Factory.php
is located in Illuminate\View
. over there you have a function called extendPush()
and you can change the "Append" method by replacing the line:
$this->pushes[$section][$this->renderCount] .= $content;
with this:
$this->pushes[$section][$this->renderCount] = $content . $this->pushes[$section][$this->renderCount];
in the last else statement.
Again, I wouldn't recommend tweaking the framework but if it's that important to your project than this is what I can offer.