【问题标题】:Twill CMS (Laravel) - Show repeater data in content editorTwill CMS (Laravel) - 在内容编辑器中显示转发器数据
【发布时间】: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


    【解决方案1】:

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

    “所以实际上有一个功能可以用于您尝试对部分产量进行的操作 调用 renderBlocks 时,您可以使用 false 作为第一个参数,表示您希望自己在父块中渲染子中继器 为了在编辑器预览中工作,有一个 twill.php 配置: twill.block_editor.block_preview_render_childs 你需要设置为 false"

    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>
                    @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>
    
    

    views\site\blocks\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>
    
    

    views\site\page.blade.php

    @extends('site.layouts.main')
    
    @section('title', 'Page Title')
    
    @section('content')
        {!! $item->renderBlocks(false) !!}
    @endsection
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多