Using ACF with WordPress Block Bindings API

Advanced Custom Fields (ACF) doesn’t have direct support for Block Bindings yet (as of 2024-03-14), but in the meantime, this seems to work by creating a custom source for block bindings:

add_action('init', function() {
	register_block_bindings_source( 'namespace/acf', array(
		'label'              => __( 'ACF Binding', 'namespace' ),
		'get_value_callback' => function(array $source_args, WP_Block $block_instance, string $attribute_name) {
			if(!isset($source_args['key'])) {
				return null;
			}
			$post_id = $block_instance->context['postId'];
			return get_field($source_args['key'], $post_id);
		},
		'uses_context'       => [ 'postId', 'postType' ]
	) );
});	

and then reference in a template (use the code editor):

<!-- wp:paragraph {
	"metadata":{
		"bindings":{
			"content":{
				"source":"namespace/acf",
				"args":{
					"key":"acf_field_name"
				}
			}
		}
	}
} -->
<p>title</p>
<!-- /wp:paragraph -->

Reference: https://developer.wordpress.org/news/2024/03/06/introducing-block-bindings-part-2-working-with-custom-binding-sources/