• jonhecky

    (@jonhecky)


    {
        "$schema": "https://schemas.wp.org/trunk/block.json",
        "name": "acf/hero-two",
        "title": "Hero Two",
        "description": "A custom hero_two block that uses ACF fields.",
        "category": "formatting",
        "icon": "admin-comments",
        "keywords": ["hero_two", "hero", "toggle", "collapse"],
        "acf": {
            "mode": "preview",
            "renderTemplate": "hero-two.php"
        },
        "attributes": {
            "style": {
                "type": "object",
                "default": {
                    "spacing": {
                        "margin": {
                            "top": "32px"
                        }
                    }
                }
            }
        },
        "supports": {
            "align": true,
            "spacing": {
                "margin": true,
                "padding": true
            },
            "anchor": true,
            "alignContent": false,
            "color": {
                "text": false,
                "background": false,
                "link": false
            },
            "alignText": false,
            "fullHeight": false
        }
    }

    Hello, I setup my block.json like this and when I load the block in the block editor and look under the styles tab it gets set to the “32px” however when I go the the front end where I am applying these styles with <?= get_block_wrapper_attributes(); ?> nothing is output. if I remove these settings in block.json and set a spacing value normally the function sets the styles without any issue.

    Why is it showing me that 32px is set on the slider, but the style is never passed to the front end? Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Mario Santos

    (@santosguillamot)

    Hello @jonhecky!

    It seems there is an issue with these default values in dynamic blocks. It has been reported in this GitHub issue and, apart from those reporting it there, I have been able to reproduce it as well. I already shared this ticket to keep track of it there, but I invite you to share your feedback and follow the discussion.

    The only thing I can think of right now is to “workaround” it somehow with the following code, but this is far from being ideal, and we should probably wait until that issue is fixed in core. Sharing just in case it helps somehow.

    <?php
    	$marginTop = isset( $attributes['style']['spacing']['margin']['top'] ) ? $attributes['style']['spacing']['margin']['top'] : '100px';
    ?>
    
    <div
    	<?php echo get_block_wrapper_attributes(); ?>
    	style="<?php echo "margin-top: " . $marginTop . ";" ;?>"
    >
    	This is my block
    </div>
    Thread Starter jonhecky

    (@jonhecky)

    Thanks for reporting it and linking those other tickets, can’t believe I didn’t run across them.

    I had your workaround for a few days before removing it and letting css specificity handle it instead, as getblockwrapperattributes sets the inline styles properly when I remove the default settings attempt in block.json. so I just set a default margin via tailwind/css.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Default block.json margin values’ is closed to new replies.