0

I have a laravel component

<section class="section {{ $classes }}">
          <div class="inner">
            <h1>{{ $heading }}</h1>
            <h2>{{ $subheading }}</h2>
            <p>{{ $copy }}</p>
           </div>

           {{ $slot }}
</section>

I render in blade template

 @component('components.section',  ['classes' => 'lightgrey'])
      @slot('heading')
      The best thing ever....
      @endslot
       @slot('subheading')

      @endslot
      @slot('copy')
      Lots of interesting words go here
      @endslot
@endcomponent

Sometime I only have an H1. How can I remove the markup if I do not have a sub heading?

shaedrich
  • 5,457
  • 3
  • 26
  • 42
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192

1 Answers1

0

From the Laravel docs: https://laravel.com/docs/5.5/blade

The @isset and @empty directives may be used as convenient shortcuts for their respective PHP functions:

@isset($records)
    // $records is defined and is not null...
@endisset

@empty($records)
    // $records is "empty"...
@endempty

I'm thinking that this would probably work:

@isset($subheading)
    @slot('subheading')

    @endslot
@endisset
kerrin
  • 3,376
  • 1
  • 26
  • 36