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?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.