Solution:
In WordPress, the PHP function localize_script()
is used to pass data from PHP to JavaScript, which could work for your scenario, eg:
<?php
function testimonial_enqueue_scripts()
{
wp_enqueue_script('testimonial-script', get_template_directory_uri() . '/template-parts/blocks/testimonial/testimonial.js');
wp_localize_script('testimonial-script', 'acf_vars', array(
'data' => 'value to send to javascript'
));
}
add_action('wp_enqueue_scripts', 'testimonial_enqueue_scripts');
?>
In your JavaScript, the data can then be accessed as acf_vars.data