Support

Account

Home Forums Gutenberg extraProps on acf blocks

Helping

extraProps on acf blocks

    • p13rnd

    • October 25, 2020 at 3:04 am

    Hi there,

    I am using acf pro to create some blocks which is working great so far.
    Now however I stumbled upon some issue which I havn’t found a solution for yet and could use some help.

    I created a custom plugin to extend some of the gutenberg core blocks behavior which is working fine:

    
    function addTWClasses(extraProps, blockType, attributes) {
    	extraProps.className = extraProps.className + ' my-custom-class';
    
    	return extraProps;
    }
     
    wp.hooks.addFilter(
    	'blocks.getSaveContent.extraProps',
    	'blob/add-tw-classes',
    	addTWClasses
    );
    

    this works well for all core blocks but not for any block created with acf_register_block_type using php.

    I am wondering why the classes do not get applied that way? Also if I output extraProps.className it say’s “acf-my-custom-block” but in frontend it does not.

    In php $block[‘className’] is null unless I add a class to the extra css classes field.

    Any help on this is much appreciated.

    Thank you.
    p13

  • I just noticed this on the register_block_type() page:

    acf_register_block_type( $settings );

    $settings

    (array) (Required) Array of arguments for registering a block type. Any argument from the JavaScript registerBlockType() function may also be used.

    So if you normally add your props in registerBlockType(), you should be able to add them when you register the ACF block.

    However, as a person with very limited JS experience, I just add any additional classes in the block template code.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.