【问题标题】:Logic in Laravel componentsLaravel 组件中的逻辑
【发布时间】:2018-04-15 01:20:00
【问题描述】:

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

【问题讨论】:

    标签: php laravel-5 components laravel-blade laravel-components


    【解决方案1】:

    来自 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-22
      • 2014-10-24
      • 2014-10-06
      • 2018-10-15
      • 1970-01-01
      • 2019-07-27
      • 2016-05-17
      • 1970-01-01
      相关资源
      最近更新 更多