GCBGutenberg
Control Blocks
v1.3.3
Buy

Multiple InnerBlocks areas in one block

Core Gutenberg gives a block one InnerBlocks area. Here is how to give one block several, each with its own allowed blocks.

A core Gutenberg block can have one InnerBlocks area: one place where your client adds their own blocks. Real designs often need two. Words beside a photo with buttons under both. A card with a body and a footer. A two-column section where each side takes different blocks.

The usual workarounds are nested Column or Group blocks, which your client can break, or two separate blocks that have to be kept side by side. Gutenberg Control Blocks (GCB) lets one block have as many InnerBlocks areas as its design needs, each with its own list of allowed blocks.

How to add the areas

In the block's template, put an <InnerBlocks> marker wherever an area goes. Number each one with data-gcb-slot, starting at 0, and give each its own allowedBlocks:

render.php
<?php $wrap = get_block_wrapper_attributes(['class' => 'split-intro']); ?><section <?php echo $wrap; ?>>  <div class="split-intro__words">    <InnerBlocks data-gcb-slot="0" allowedBlocks='["core/heading", "core/paragraph"]' />  </div>  <img class="split-intro__photo" src="<?php echo esc_url($attributes['photo']['url'] ?? ''); ?>" alt="">  <div class="split-intro__actions">    <InnerBlocks data-gcb-slot="1" allowedBlocks='["core/buttons"]' />  </div></section>

That's the whole change. Each area can also have its own template (the blocks it starts with) and templateLock.

What your client gets

  • Each area where it sits. Your client fills an area in its own place in the design, not in a list under the block. An empty area shows a + that offers only the blocks that area allows.
  • Each area its own rules. In the example, the first area takes headings and paragraphs, and the second takes only buttons. Inside an area, your client can add, move and remove as many blocks as they like.
  • Areas that stay put. The areas belong to the design. Your client can fill them but can't move, remove or add an area.
  • Fields alongside. The block can still have typed fields, like the photo above, next to its areas. Use fields for the parts that must stay on brand, and areas for the parts your client should shape.

How it's stored

Each area is saved as a child block, gcblite/area, with a slot attribute holding the marker's number, and the area's blocks go inside it. On the page, each area's blocks are printed where its marker stands. A headless front end receives the areas as the block's innerBlocks, each with attrs.slot.

Adding areas to a block that's already in use is safe. Existing content is moved into the areas the next time the page is opened in the editor, and nothing is dropped.

One rule to know

A block that repeats child blocks with a <Repeater> doesn't get areas, because its children are the repeated items. Put the repeater in a child block instead.

More in the docs: InnerBlocks, the repeater and areas. See it working in the InnerBlocks feature page, or try it in your browser.

Build anything in the block editor

Every licence includes all features and a year of updates and support.

Buy GCB from $8.25 a month See pricing