0

We've been working with block patterns.

So we built the blocks, for instance, with Divs as the structure. But the client comes back 'for accessibility, we need the structure to be UL/LI.

So we modify our code, but some blocks are already added in the site, and it doesn't look like they are updating.

Is there a way to force WP ro regenerate blocks by keeping the content, but changing the structure around it?

1

1 Answer 1

0

It would heavily depend on your block layout and how you format your block data & inner blocks.

When using the deprecation, you just need to think of it like making an acceptable format to recognise your old markup, with a migrate function if you need to help the conversion along.

Add all your old attributes and if you need to do anything more complicated (like parsing and converting inner blocks, or adding attributes etc... then use the migrate function.

const { registerBlockType } = wp.blocks;

registerBlockType('gutenberg/block-with-deprecated-version', {
    // ... other block properties go here

    attributes: {
        content: {
            type: 'string',
            default: 'some random value',
        },
    },

    save(props) {
        return <ul>{{{ -- new block save stuff -- }}}</ul>;
    },

    deprecated: [
        { // Essentially a copy of your old attributes and save function goes here
            attributes: { // These will be the 'old' attributes - 
                content: {
                    type: 'string',
                    default: 'some random value',
                },
            },

            save( props ) {
                return <div>{{{-- OLD block save stuff -- }}}</div>; 
            },
        },
    ],
});

There are some examples shown on the Codex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.