kokiddp / carbon-fields-innerblocks
Adds InnerBlocks support to Carbon Fields blocks.
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/kokiddp/carbon-fields-innerblocks
Requires
- php: >=7.4
- htmlburger/carbon-fields: ^3.3
README
This is a Composer package that extends Carbon Fields to support InnerBlocks inside Gutenberg blocks.
Features
- Gutenberg
InnerBlocksintegration - 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