For those looking for a PHP solution. A good place to do this is in the render_callback function. One thing to keep in mind with this solution is that this only works on first load, which is good enough for the frontend, but it will not work accurately in the Gutenberg editor itself once you start editing and/or moving blocks.
acf_register_block_type([
'name' => 'blockname,
'render_callback' => 'my_acf_block_render_callback',
]);
function my_acf_block_render_callback($block) {
global $block_index;
$index = $block_index++;
// Do whatever else you need to do and make sure you pass the $data array to your template.
}
Related Posts:
- Gutenberg blocks (block editor) with get_the_excerpt and get_the_content, using ACF
- $attributes not defined in block.json PHP template for ACF blocks
- How to use ACF fields content in backend?
- Unable to edit custom post type, editor crashes. What to do?
- Replace multiple RichText components in a single block – wp.blockEditor.RichText multiline prop is deprecated
- How does Gutenberg handle translations in React?
- Saving post meta using the new EntityProvider APIs
- Implement Panel Color Inspector Control in Gutenberg
- gutenberg dynamic block is returning 404
- Gutenberg InspectorControls is deprecated, how to add custom block settings?
- How should you internationalize javascript spread in multiple files but build in one?
- How to set column widths in a CPT block template?
- Access GutenBerg data with Javascript?
- Only show focused toolbar for Gutenberg Block with Multiple text fields
- Adding a custom PanelColorSettings control to a core block, and using the color slug in a custom className
- Enhancing Gutenberg featured image control
- Is it possible to create column width presets in Gutenberg?
- How to define a Block Style in an Innerblocks template
- Option for removing block not appearing in custom gutenberg block
- Testing custom themes / plugins under Gutenberg
- Gutenberg LinkControl suggestionsQuery not working
- Gutenberg – How to prevent block from being deleted and reordered/moved
- WordPress Gutenberg Columns block
- How to Add a Container Class to Standard Gutenberg Blocks
- How to check if post has Video or Gallery block in Gutenberg blocks?
- Gutenberg – button to parse and format all blocks?
- Custom WP Block using Inner Blocks crashes editor, doesn’t save content
- Gutenberg Button Border Radius Default
- Disable title block on edit screen for a custom post type
- Gutenberg: Block validation fails if editor is reloaded or post is edited. data.getBlocks(); is empty in save function
- Delete a Gutenberg Block Programmatically?
- Can Gutenberg be used as an editor on a page?
- Import external data into post using custom Gutenberg block
- How do a I add an attribute to element (when using block theme)?
- How to transform block variant to default version?
- How can I add a color picker to a custom Gutenberg block which includes the default system palette from theme.json?
- How to makes Custom Post Type posts as Gutenberg’s patterns?
- Can’t run WP e2e-test-utils because the browser exits on login?
- Modify the InnerBlocks ‘Add block’ block appender label
- Do I need wp-tinymce-js?
- Gutenberg TextareaControl escapes html
- Block editor fails to update HTML section when the word “from” is in source code
- Block Controls not showing
- Gutenberg and FSE: How to exclude a block from full site editing
- Disable only one Gutenberg block programatically / coblock/maps not listed in blocks
- How to select block variation from BlockVariationPicker
- Editable button with RichText for Gutenberg custom block
- How Do I Prevent An Image From Automatically Adjusting In Guttenberg Block Gallery?
- Getting ACF Field in Page – From the Footer
- Using wp_set_script_translations without manually registering the script
- Why am I getting the error: Cannot update a component (`Unknown`) while rendering a different component (`Edit`)?
- Update number of posts when attribute changed
- Connect WordPress and react front-end
- Setting fontSize within core/heading
- Unable to edit server side rendered block
- Exclude certain Gutenberg blocks from search results
- WordPress Dynamic Block with multiple checkboxes
- Embedded block editor in block editor
- useSelect in block Edit always returns default store value
- Count Gutenberg blocks on the front-end?
- How to call a react hook on edit of registerBlockType?
- Why does the paragraph block automatically add class?
- How can I block embeds and show an individual preview image per block?
- add arrow icon next to read more link on latest posts gutenberg block
- Create a trailing block with programatically generated Gutenberg columns
- How to make attributes unique to Gutenberg blocks
- How to check title is being entered in Title Case?
- Gutenberg link of internal page not showing
- How do I trigger the sidebar reveal for my sidebar plugin in the Gutenberg editor?
- Create Gutenburg Block to render inline SVG
- Gutenberg blocks not full width
- Custom Image Gutenberg Block With Caption
- How to make a block similar to another block
- Gutenberg: How to enqueue scripts conditionally in render_callback by checking for an attribute?
- How can I reintroduce autocompletion of Gutenberg components in Visual Code?
- Blocks – any way to have editor honor width percentages on child blocks?
- Using `esc_attr( get_block_wrapper_attributes() )`, results in `class=””wp-block-foo””`
- How to display dynamic block editor on front-end?
- Debouncing Input value with block attributes
- Using the block theme in production
- When using the MediaPlaceholder component, will skipping blobUrl handling break something?
- Pass component name in onChange [closed]
- Add another option to default link control settings panel?
- Different style options for the same block depending where it is used
- How to extract ‘intro’ block from page content, but later strip from page main content
- Add a new option to Social Link block
- Editing Inline fonts/typeface using the block editor
- What is the proper way of using React Hooks in Gutenberg on frontend?
- How to add Gutenberg editor on frontend page?
- WordPress gutenberg block serverside rendering html elements not showing up
- Gutenberg: change block Components Popover properties
- Unable to register a block using block.json in Block Editor
- add_editor_style now copying html styles to .editor-styles-wrapper?
- Building my first ever Gutenberg block
- Controlling or disabling Gutenberg editor panning/focus on a custom slider block
- How do i create a switch for responsive devices?
- wordpress 6.4.2 gutenberg custom block array attributes saving problem?
- Set a default overlay color for the Core Cover block in theme.json
- Add Gallery items programmatically inside an InnerBlock
- Is it possible to add settings to a search block in Gutenberg?