0

我为我的“主要内容”创建了一个块,这个块使用转发器字段来添加多个按钮。

它在我的前端正确呈现,但按钮不包含在 Twill 的内容编辑器中。

当我从mainContent.blade.php中删除 @yield和从buttons.blade.php中删除 @section 时,按钮确实会显示在前端和内容编辑器中,但它们将被添加到我的 mainContent 块之外。

如何让按钮显示在 Twill 的拖放内容编辑器中?

意见/管理/块/mainContent.blade.php

@twillBlockTitle('MainContent')
@twillBlockIcon('text')

...

@formField('repeater', [
'type' => 'buttons',
'name' => 'button_repeater'
])

视图/管理员/中继器/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'
])

视图\站点\块\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>

视图\站点\块\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
4

1 回答 1

0

在 Twill Discord 支持(感谢 ifox)的帮助下,我得到了它的工作。

“因此,在调用 renderBlocks 时,实际上有一个功能可用于您尝试对部分 yield 执行的操作,您可以使用 false 作为第一个参数来指示您希望自己在父块中渲染子中继器并使其正常工作在编辑器预览中,有一个 twill.php 配置:twill.block_editor.block_preview_render_childs 需要设置为 false”

视图\站点\块\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>
                @foreach ($block->children->where('type', 'buttons') as $child)
                    @include('site.blocks.buttons', ['child', $child])
                @endforeach
            </div>
            <div class="col-12 col-lg-6">
                <img class="img-fluid" src="{{ $block->image('image', 'desktop') }}" />
            </div>
        </div>
    </div>
</section>

视图\站点\块\buttons.blade.php


<a href="{{ $child->input('url') }}" class="{{ $child->input('type') }} btn">
    @if (!empty($child->input('fa_icon')))
        <i class="fa {{$child->input('fa_icon')}}"></i>
    @endif
    <span>
        {{ $child->input('label') }}
    </span>
</a>

意见\网站\page.blade.php

@extends('site.layouts.main')

@section('title', 'Page Title')

@section('content')
    {!! $item->renderBlocks(false) !!}
@endsection

于 2021-08-04T12:25:10.333 回答