0

我有一个 laravel 组件

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

           {{ $slot }}
</section>

我在刀片模板中渲染

 @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

有时我只有一个H1。如果我没有子标题,如何删除标记?

4

1 回答 1

0

来自 Laravel 文档: https ://laravel.com/docs/5.5/blade

@isset@empty指令可以用作它们各自 PHP 函数的便捷快捷方式:

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

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

我认为这可能会起作用:

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

    @endslot
@endisset
于 2017-11-05T09:52:41.230 回答