php - ACF Repeater for registering Gutenberg Blocks
one text
I am working on a template where I want to make a function that I can use the repeater field from ACF to combine that with the acf_register_block_type();
.
What I have is the following:
<?php
$rows = get_field('register_block');
if( $rows ) {
foreach( $rows as $row ) {
$register_block_name_function = $row['register_block_name'];
$register_block_name = $row['register_block_name'];
function $register_block_name_function() {
acf_register_block_type(array(
'name' => $register_block_name,
'title' => __('3 Columns'),
'render_template' => '/acf/blocks/gutenberg/columns-3.php',
'category' => 'blocks',
'mode' => 'auto',
'supports' => array(
'align' => true,
'mode' => true,
'anchor' => true,
),
'icon' => array(
// Specifying a background color to appear with the icon e.g.: in the inserter.
'background' => '#B53A73',
// Specifying a color for the icon (optional: if not set, a readable color will be automatically defined)
'foreground' => '#FFF',
// Specifying a dashicon for the block
'src' => 'align-left',
),
));
}
// Check if function exists and hook into setup
if (function_exists('acf_register_block_type')) {
add_action('acf/init', $register_block_name_function);
}
}
}
?>
Is there a way that I can use 1 ACF Repeater to create multiple Gutenberg bocks by just adding a name.
Source