Php 条件叶片组件槽

Php 条件叶片组件槽,php,blade,laravel-blade,Php,Blade,Laravel Blade,我有一个名为persons的刀片组件,它有不同的插槽,我想填充 {{$name} {{$information} 如您所说,最好在上层检查它们,但请注意,如果它们有名称slot,您应该将某些内容传递到slot中,因此您应该调用: @slot('myslot') @if($myobject->value) <h5> Show </h5> @endif @endslot @slot('myslot')) @如果($myobje

我有一个名为persons的刀片组件,它有不同的插槽,我想填充


{{$name}
{{$information}

如您所说,最好在上层检查它们,但请注意,如果它们有名称slot,您应该将某些内容传递到slot中,因此您应该调用:

@slot('myslot')
  @if($myobject->value)
    <h5>
       Show
    </h5>
  @endif
@endslot
@slot('myslot'))
@如果($myobject->value)
显示
@恩迪夫
@端槽

如您所说,最好在上层检查它们,但请注意,如果它们有名称slot,您应该将某些内容传递到slot中,因此您应该调用:

@slot('myslot')
  @if($myobject->value)
    <h5>
       Show
    </h5>
  @endif
@endslot
@slot('myslot'))
@如果($myobject->value)
显示
@恩迪夫
@端槽

这是很久以前的事了,但是您可以使用null coalesce操作符来定义默认值

<div class="person">
  <img src="{{ $image_url }}" alt="{{ $image_alt }}">
  {{ $name ?? '' }}
  {{ $information ?? '' }}
  <a class="button button-primary" href="{{ $link }}" target="_blank">Homepage</a>
</div>

{{$name???''}}
{{$information???'}

这是很久以前的事了,但是您可以使用null coalesce操作符来定义默认值

<div class="person">
  <img src="{{ $image_url }}" alt="{{ $image_alt }}">
  {{ $name ?? '' }}
  {{ $information ?? '' }}
  <a class="button button-primary" href="{{ $link }}" target="_blank">Homepage</a>
</div>

{{$name???''}}
{{$information???'}

使用
@if
和null强制运算符并设置默认值:


@如果($image\u url??null)
@恩迪夫
{{$name???'No name'}
{{$information??null}
@如果($link??null)
@恩迪夫

使用
@if
和null强制运算符并设置默认值:


@如果($image\u url??null)
@恩迪夫
{{$name???'No name'}
{{$information??null}
@如果($link??null)
@恩迪夫