定制 secondnetwork/voyager-page-blocks 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

secondnetwork/voyager-page-blocks

Composer 安装命令:

composer require secondnetwork/voyager-page-blocks

包简介

Ahoy! - A package to implement page blocks into Voyager

README 文档

README

This repository is only Voyager Page Blocks not the Voyager Frontend Package

Prerequisites

Installation

1. Require this Package in your fresh Laravel/Voyager project

composer require secondnetwork/voyager-page-blocks

2. Run the Installer

php artisan voyager-page-blocks:install

3. (Optional) Seed the database with example page blocks.

php artisan voyager-page-blocks:seed

Creating & Modifying Blocks

Page blocks are created & configured in 2 steps:

  1. Define the block - in /config/page-blocks.php
  2. Build the block's HTML layout - create the template in /resources/views/vendor/voyager-page-blocks/blocks

1. Define a Block

Familiarize yourself with /config/page-blocks.php. This is where you'll define each block - you'll tell it which fields the block should have (for the admin to manage) and which Blade template it should use on the frontend.

  • Each array inside this configuration file is a page block
  • Each block contains fields
  • Each field contains a unique field key
  • Each field is based on a Voyager Data Type

The below table explains what each property does and how it is relevant to the block itself:

Key Purpose
Root key This is the name of your page block, used to load the configuration
name This is the display name of your page block, used in the block 'adder'
fields This is where your page block fields live (text areas, images etc)
fields => field The content name of your field, used to store/load its content
fields => display_name The display name of this field in the back-end
fields => type The data row type that this field will use (check TCG\Voyager\FormFields)
fields => required Self-explanatory, marks this field as required or not (not available for all partials)
fields => placeholder Self-explanatory, adds a placeholder to the field (not available for all partials)
fields => details Used for selects/checkboxes/radios to supply options
template This points to your blade file for your block template
compatible TBA

2. Build the HTML

When you're ready to start structuring the display of your block, you'll need to create (or override our defaults) your blade template (located at /resources/views/vendor/voyager-page-blocks/blocks/your_block.blade.php) and use the accessors you defined in your module's configuration file to fetch each fields data ({!! $blockData->image_content !!}).

Example. Putting it all together

Let's say we want to create a new block with 1 WYSIWYG editor, called 'Company Overview'.

Step 1. Define the new block

In /config/page-blocks.php, we'll add:

$blocks['company_overview'] = [
    'name' => 'Company Overview',
    'template' => 'voyager-page-blocks::blocks.company_overview',
    'fields' => [
        'content' => [
            'field' => 'content',
            'display_name' => 'Company Overview Content',
            'type' => 'rich_text_box',
            'required' => 1,
            'placeholder' => '<p>Lorem ipsum dolor sit amet. Nullam in dui mauris.</p>',
        ],
    ],
];

Step 2. Build the Controller and Blade View

PagesController

class PagesController extends Controller
{
    protected $theme = '';

    public function index()
    {
        $page = Page::where('slug', 'startseite');
        $page = $page->firstOrFail();
        $block = DB::table('page_blocks')
            ->where('page_id', '=', $page->id)
            ->where('is_hidden', '=', '0')
            ->orderBy('order', 'asc')
            ->get();
        return view('theme::pages.default', compact('page', 'block', 'posts'));
    }

Blade View Template

@if (!empty($block))
@foreach($block as $blockTemp)
    @if (!empty($blockTemp->type))
        @php
        $template = $blockTemp->path;
        $blockData = json_decode($blockTemp->data);
        @endphp
        
        @include('theme::blocks.'.$template)
        
    @else
        <div class="page-block">
            <div class="callout alert">
                <div class="grid-container column text-center">
                    <h2><< !! Warning: Missing Block !! >></h2>
                </div>
            </div>
        </div>
    @endif
@endforeach
@else
<h1>
  {{ $page->title }}
</h1>
<div class="page-content">
  {!! $page->body !!}
</div>
@endif

Step 3. Add the block to a page

Next, jump into the Voyager Admin > Pages and click 'Content' next to a page. You'll now be able to select Company Overview from the 'Add Block' section. Add the block to the page, drag/drop it into place, edit the text etc.

Troubleshooting

It is important to sanitise your field output, null values will cause errors.

It is very important that you follow the naming scheme that is setup in the example page blocks as the keys reference other cogs in the system to stitch the blocks together. There are example blocks already set up in the resources/views directory and configuration file for you to get started.

secondnetwork/voyager-page-blocks 适用场景与选型建议

secondnetwork/voyager-page-blocks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 272 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「page」 「laravel」 「frontend」 「blocks」 「voyager」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 secondnetwork/voyager-page-blocks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 secondnetwork/voyager-page-blocks 我们能提供哪些服务?
定制开发 / 二次开发

基于 secondnetwork/voyager-page-blocks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 272
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-10