【发布时间】:2021-10-09 09:23:21
【问题描述】:
我为我的“主要内容”创建了一个块,这个块使用中继器字段来添加多个按钮。
它在我的前端正确呈现,但按钮不包含在 Twill 的内容编辑器中。
当我从 mainContent.blade.php 中删除 @yield 并从 buttons.blade.php 中删除 @section 时,按钮确实会显示在前端和内容中编辑器,但它们将被添加到我的 mainContent 块之外。
如何让按钮显示在 Twill 的拖放内容编辑器中?
views/admin/blocks/mainContent.blade.php
@twillBlockTitle('MainContent')
@twillBlockIcon('text')
...
@formField('repeater', [
'type' => 'buttons',
'name' => 'button_repeater'
])
views/admin/repeaters/buttons.blade.php
@twillRepeaterTitle('Buttons')
@twillRepeaterMax('4')
@formField('input', [
'name' => 'label',
'label' => 'Button text'
])
@formField('input', [
'name' => 'url',
'label' => 'Button url',
'fieldNote' => 'https://google.com/'
])
@formField('select', [
'name' => 'type',
'label' => 'Button type',
'placeholder' => 'Select a button type',
'options' => [
[
'value' => 'btn-primary',
'label' => 'Primary'
],
[
'value' => 'btn-secondary',
'label' => 'Secondary'
],
[
'value' => 'btn-link',
'label' => 'Link'
],
]
])
@formField('input', [
'name' => 'fa_icon',
'label' => 'Font Awesome icon code',
'fieldNote' => 'fa-users'
])
views\site\blocks\mainContent.blade.php
<section class="block block-main-content">
<div class="container">
<div class="row">
<div class="col-12 col-lg-6">
<h2>{{ $block->input('title') }}</h2>
<p>{{ $block->input('content') }}</p>
@yield('buttons')
</div>
<div class="col-12 col-lg-6">
<img class="img-fluid" src="{{ $block->image('image', 'desktop') }}" />
</div>
</div>
</div>
</section>
views\site\blocks\buttons.blade.php
@section('buttons')
<a href="{{ $block->input('url') }}" class="{{ $block->input('type') }} btn">
@if (!empty($block->input('fa_icon')))
<i class="fa {{$block->input('fa_icon')}}"></i>
@endif
<span>
{{ $block->input('label') }}
</span>
</a>
@append
【问题讨论】:
标签: php laravel content-management-system twill laravel-twill