I have a blade view which makes use of my template using
@extends('layouts.master')
Within that template I want to show 2 buttons if the section on my child view is true, rather than having to include them in every child view that makes use of the template.
For example, my layout (snippet)
@yield('buttons')
<div>
<button>BUTTON 1</button>
<button>BUTTON 2</button>
</div>
@show
@yield('content)
Here's my child view
@extends('layouts.master')
@section('buttons',false)
@section('content')
<p>Hello world!</p>
@endsection
I know it doesn't work the way I've tried but is something like this possible? I've also tried wrapping the @yield('buttons') in an @if but this isn't possible as @yield can only be used in a function apparently.
Within in my master layout I replace @yield with @section
@section('buttons')
<button>BUTTON 1</button>
<button>BUTTON 2</button>
@endsection
Within my child view I use
@section('buttons','')
This replaces the default, if you wish to keep the default and place your additional content before or after then use @parent before or after your additional content for example in my child view:
@section('buttons')
Additional content to be inserted before the buttons in my master layout.
@parent
@endsection
Outputs:
Additional content to be inserted before the buttons in my master layout. BUTTON 1BUTTON 2
Reference: https://laravel.com/docs/5.5/blade