Closed Log1x closed 1 year ago
Perfect 👌
We currently do very similarly by passing through the with()
method + we usually include allowed_blocks
to restrict which blocks can be added (if relevant):
// app/Blocks/SomeBlock.php
public function with() {
return [
...
'allowed_blocks' => $this->allowed_blocks(),
'template' => $this->block_template(),
];
}
public function block_template() {
return esc_attr(wp_json_encode([
['core/heading', [
'level' => 2,
'placeholder' => 'Your heading',
'fontSize' => 'sm',
]]
]));
}
public function allowed_blocks() {
return esc_attr(wp_json_encode([
'core/heading',
'core/buttons',
]));
}
{{-- some-block.blade.php --}}
<InnerBlocks
template="{!! $template !!}"
allowedBlocks="{!! $allowed_blocks !!}"
/>
This PR adds native support for the InnerBlocks
template
property making it easy + clean to add block templates to your ACF blocks.A simple template adding a heading and paragraph would look something like:
I couldn't get block nesting as pretty as I wanted (e.g. when using
core/column
andcore/columns
) but it can be done using theinnerBlocks
attribute.After adding the
$template
property to your block class you would then pass$block->template
totemplate
in<InnerBlocks />
.Open to feedback/suggestions.