arnaudbagnis/acf-gutenberg-custom-block
Composer 安装命令:
composer require arnaudbagnis/acf-gutenberg-custom-block
包简介
Acf Gutenberg custom Block for Lumberjack Framework
README 文档
README
This package provides a custom block creation functionality for the Lumberjack theme with the help of ACF Pro plugin. It includes a Provider and an AbstractBlock class that allows you to create custom blocks quickly and easily.
Installation
To use this package, you need to have ACF Pro installed and activated in your project. You can install this package via composer by running the following command:
composer require arnaudbagnis/acf-gutenberg-custom-block
Usage
Create a new block in your theme's block directory by extending the AbstractBlock class provided by this package. Here is an example:
<?php
namespace App\Guttenberg\Block;
use Timber\Timber;
class MyCustomBlock extends AbstractBlock
{
public static function getName(): string
{
return "my-custom-block";
}
public static function getTitle(): string
{
return "My Custom Block";
}
public static function getDescription(): string
{
return "This is a description";
}
public static function getCategory(): string
{
return "formatting";
}
public static function getIcon(): string
{
return "admin-comments";
}
public static function getKeywords(): array
{
return array('my-custom-block', 'quote');
}
public static function getExample(): array
{
return array();
}
public static function getEnqueueAssets()
{
// Add a style/js for only this block
return null;
}
public static function getLocalFieldGroup(): array
{
// Add a php field acf block for stay in memories
return [];
}
public static function getController($block)
{
$context = Timber::context();
// retrieve an ACF field here
$context['settings'] = [
'title' => get_field('title'),
'description' => get_field('description'),
'image_right' => get_field('image_right'),
'cta' => get_field('cta'),
'explanations' => get_field('explanations'),
];
Timber::render('templates/blocks/' . static::getName() . '.twig', $context);
}
}
Create a block.php file in your theme's config directory and add the following code to it:
<?php
use App\Guttenberg\Block\MyCustomBlock;
return [
'styles' => [
'./assets/dist/main.css'
],
'blocks' => [
MyCustomBlock::class,
]
];
The styles array allows you to add global styles to the Gutenberg editor, while the blocks array allows you to add the blocks you created.
That's it! Your custom block is now ready to be used in the Gutenberg editor.
arnaudbagnis/acf-gutenberg-custom-block 适用场景与选型建议
arnaudbagnis/acf-gutenberg-custom-block 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 602 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 arnaudbagnis/acf-gutenberg-custom-block 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arnaudbagnis/acf-gutenberg-custom-block 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 602
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: mit
- 更新时间: 2023-03-13