Laravel组件中的逻辑

时间:2017-11-02 13:32:00

标签: php laravel-5 components laravel-blade

我有一个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。如果我没有子标题,如何删除标记?

1 个答案:

答案 0 :(得分: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