Support

Account

Home Forums Gutenberg Check if Innerblocks is empty

Unread

Check if Innerblocks is empty

  • Is there any way to wrap <InnerBlocks> in a conditional statement to see if it’s empty or not?
    I have an ACF block with innerblocks, much similiar to how the core Cover block works. Sometimes innerblocks is not needed, but since I provide a template the markup outputs even if the blocks are empty.

    Of course I (the client) can remove the blocks from admin and so on but it would be a nice solution if we can check for empty if someone forgets to remove them.


    <?php
    $template = array(
    array('core/heading', array(
    'level' => 2,
    'placeholder' => 'Title',
    )),
    array('core/paragraph', array(
    'placeholder' => 'Content',
    ) )
    );
    ?>
    <div>
    <InnerBlocks template="<?php echo esc_attr( wp_json_encode( $template ) ); ?>" />
    </div>

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.