The only I can think of is to use [parse_block()][1]
and [render_block()][1]
parse_block will parse html blocks into an array, and render_block will convert an array into content.
Here is an example of how you can achieve what you want using the above functions (code not tested):
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
}
?>
<?php
if (has_post_thumbnail()) {
?>
<header class="entry-header">
<?php
the_title('<h1 class="entry-title">', '</h1>');
?>
</header>
<?php
}
?>
<?php
$renderd_content = "";
$parsed_blocks = parse_blocks($post->content);
foreach ($parse_blocks as $block_index => $block_attr) {
if ($block_index === 1 && !has_post_thumbnail()) {
$renderd_content .= the_title('<h1 class="entry-title">', '</h1>', false);
}
$renderd_content .= render_block($block_attr);
}
echo $renderd_content;
?>
Here is a link that provides more examples of this and discuss ACF as well.
https://www.billerickson.net/access-gutenberg-block-data/#acf-block-data