kokiddp/carbon-fields-innerblocks

Adds InnerBlocks support to Carbon Fields blocks.

v0.1 2025-07-17 00:58 UTC

This package is auto-updated.

Last update: 2025-08-17 01:12:41 UTC


README

This is a Composer package that extends Carbon Fields to support InnerBlocks inside Gutenberg blocks.

Features

  • Gutenberg InnerBlocks integration
  • Support for multiple innerblock fields per block
  • Unlimited nested innerblocks
  • Configurable attributes:
    • allowed_blocks()
    • template()
    • template_lock()
    • orientation()
  • Prevents use outside Gutenberg (e.g. options pages)

Installation

composer require kokiddp/carbon-fields-innerblocks

The field will be automatically registered when the package is autoloaded by Composer.

Usage Example

use Carbon_Fields\Block;
use Carbon_Fields\Field;

Block::make('Content Block')
    ->add_fields([
        Field::make('text', 'section_title', 'Section Title'),
        Field::make('innerblock', 'main_content', 'Main Content')
            ->set_allowed_blocks(['core/paragraph', 'core/image'])
            ->set_template([
                ['core/paragraph', ['placeholder' => 'Start typing...']]
            ])
            ->set_template_lock(false)
            ->set_orientation('vertical'),
        Field::make('innerblock', 'sidebar_content', 'Sidebar Content')
    ])
    ->set_render_callback(function ($fields, $attributes, $inner_blocks) {
        echo '<div class="my-block">';
        echo '<h2>' . esc_html($fields['section_title']) . '</h2>';
        echo '<div class="main">' . $inner_blocks . '</div>';
        echo '<div class="sidebar">' . $inner_blocks . '</div>';
        echo '</div>';
    });

Limitations

  • This field only works inside Gutenberg block contexts
  • It will log an error and render nothing if used in options, users, terms, etc.

License

MIT © Gabriele Coquillard