Reputation: 1172
I need to duplicate a piece of html in my blade template but it's so small that I don't want to create a new file. Can I create a section in the same file that I use it? for example:
@section('small')
<div>small piece of html</div>
@endsection
@include('small')
<div>some html here</div>
@include('small')
Upvotes: 0
Views: 2001
Reputation: 1076
I think @stack
and @push
is what you need instead of @section
Let's say you're going to use that on other file
Page 1:
@stack('small')
Page 2 :
@push('small')
<div>small piece of html</div>
@endpush
@push('small')
<div>some html here</div>
@endpush
Upvotes: 2
Reputation: 144
Do you mean duplicate @section? if yes, so create @yield with another name, and call both sections in the same template.
Page 1:
@yield('section1')
@yield('section2')
Page 2 :
@section('section1')
<div>small piece of html</div>
@endsection
@section('section2')
<div>some html here</div>
@endsection
Upvotes: 0
Reputation: 329
You need to use Component with Laravel and make your template in a example.blade.php and set your variables in the component, and send the variables to the component while calling it like:
@component('alert', ['foo' => 'bar'])
...
@endcomponent
So it's in a different file but while sending the variables to the component, it can be efficient.
Upvotes: 0