We can use a section
to define some HTML and then yield
that somewhere else.
So why do we have stacks? https://laravel.com/docs/5.2/blade#stacks
It's doing exactly the same thing with different keywords, but has fewer options (No inheritance).
@push('scripts')
<script src="/example.js"></script>
@endpush
<head>
<!-- Head Contents -->
@stack('scripts')
</head>
Can be done with section:
@section('scripts')
<script src="/example.js"></script>
@endsection
<head>
<!-- Head Contents -->
@yield('scripts')
</head>
Stack is someway appropriate for scripts , with stack you can Append as much as you need .
Append …
As you can see the scripts stack will be appended under the script tag of example.js . So you can push special scripts for each view .
I might be mistaken, but the difference is not only semantically, but in behaviour as well. With @push you append as many times as needed to a stack, while (by default) you may fill @section only once in your views. In some situations this comes in handy when you need to add content from different locations across your template files or in loops:
index.blade.php:
master.blade.php
result: