Логика в компонентах Laravel

У меня есть компонент 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. Как я могу удалить разметку, если у меня нет подзаголовка?

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
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector