Your Location is: Home > Advanced-custom-fields

get_fields is empty after inserting an ACF gutenberg block

From: San Marino View: 1448 Thomas Wegerer 


we just integrated timber into our acf-gutenberg-block setting, and we love it. ;) There is one thing that doesnt work.

Our ACF Blocks have prefilled values like a "dummy" headline. But when a backend user adds a block into the gutenberg view, the get_fields() inside our render_callback function is empty. The user then changes the headline and then get_fields brings up all the fields and their values.

any idea how to fix this problem on the first load of an acf block?

the callback function looks like this (just like the one in the documentation)

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();
    // Value for detecting editor-view in twig (like is admin())
    $context['is_preview'] = $is_preview;

    // Render the block.
    Timber::render('blocks/' . $block['template-name'] . '.html.twig', $context);



Best answer