Hi. I want to used InnerBlocks on multiple places inside an acf block like so:
<?php
$allowed_blocks_left = [''core/list', 'core/button', 'core/image'];
$allowed_blocks_right = ['core/heading', 'core/paragraph'];
?>
<div <?php echo $anchor; ?>class="<?php echo esc_attr($class_name); ?>">
<div class="container">
<div class="row">
<div class="col-12 col-md-6">
<InnerBlocks allowedBlocks="<?php echo esc_attr(wp_json_encode($allowed_blocks_left)); ?>" />
</div>
<div class="col-12 col-md-6">
<InnerBlocks allowedBlocks="<?php echo esc_attr(wp_json_encode($allowed_blocks_right)); ?>" />
</div>
</div>
</div>
</div>
Is this possible? At the moment the content of “InnerBlocks” simply duplicates itself.
It’s easy!
Just change the way You think about the inner blocks as they’ll always have “only one place” to include the inner blocks.
Is all about making more blocks + limit blocks that You can insert + default block template.
- Make a container block with innerblocks and name it like “Two Columns: Layout A”
- Make a child block called “Two Columns: Layout A – Left Column”
- Make a child block called “Two Columns: Layout A – Right Column”
Now create template with lock function for each blocks mentioned above:
- 1. Container – template with allowed only: 2 and 3 (blocks left & right column)
- 2. Left Col. template with allowed only: ‘core/list’, ‘core/button’, ‘core/image’
- 3. Right Col. template with allowed only: ‘core/heading’, ‘core/paragraph’
More to read: resources/acf_register_block_type – look for: allowedBlocks, template & templateLock.
Thank you! That helped me alot. Sometimes it can be so simple… ^^
Hello! I have the same problem. Can you show the solution?
If You never did it before the good starting point would be to see InnerBlocks with ACF blocks written by Bill Erickson.