How to get ACF value inside Gutenberg Block from another page or template? I’m using Timber too

You’ll need to set a render callback when you create your ACF block:

acf_register_block_type( array(
    'name'            => 'example-block',
    'title'           => __( 'Example Block', 'your-text-domain' ),
    'description'     => __( 'A custom example block.', 'your-text-domain' ),
    'render_callback' => 'my_acf_block_render_callback',
    'category'        => 'formatting',
    'icon'            => 'admin-comments',
    'keywords'        => array( 'example' ),
) );

Then in that function you call Timber functions like in a page template:

function my_acf_block_render_callback( $block, $content="", $is_preview = false ) {
    $context = Timber::context();

    // Store block values.
    $context['block'] = $block;

    // Store field values.
    $context['fields'] = get_fields();

    // Store $is_preview value.
    $context['is_preview'] = $is_preview;

    // Render the block.
    Timber::render( 'block/example-block.twig', $context );
}

After that the block will properly render when output using {{ post.content }} or anything else that uses the standard WordPress filters to display the_content().

More info is available in Timber’s documentation, which is where I got these snippets.

tech