-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
manually duplicate serialized block #386
Comments
I'm solving it now by generating the block id with |
Hi @pwkip Thanks for the question. Yes, each block requires a unique ID in the format "block_x". As you have encountered, if two blocks use the same ID, they will update each other's content, similar to if two Posts had the same ID 👍. |
Hey @elliotcondon Is there any progress in changing the IDs automatically if they already exist? |
@CreativeDive Unfortunately not. The conversation with Gutenberg team went stale. I'm not aware of any API changes that would allow us to listen for the paste block event. |
I do believe the block IDs update automatically as long as you duplicate the block via the Gutenberg interface. When you duplicate the block code manually, however, it seems like you need to update the block id manually as well. I guess ACF could do a sanity check on post save, and ensure that there are no duplicate block IDs. Or are there valid cases where 2 blocks can have the same ID? |
@elliotcondon and @pwkip I think it would prevent many problems in the future if the ID was updated automatically. I see a big problem in copying and pasting blocks. I use e.g. post types to edit other areas of a website with the gutenberg editor. For example, if I copy an ACF block from post type A to post type B. Then the block from post type B always has the properties of the block from post type A. |
@CreativeDive @pwkip We are all in agreement here 👍. The best case scenario is to hook into the "paste block" event and generate a fresh block ID. We have a solution for this when duplicating a block within the same post, but not when pasting a block (or using a block within other features such as block-patterns) into a post. You can follow the discussion on this GitHub issue, but please do not use this as a forum to push the feature-request. The Gutenberg team do not respond well to this kind of behavior. WordPress/gutenberg#23377 |
Maybe not so much an issue, but just something I'm wondering about.
Say, I have a block like this:
But I would like to duplicate it manually, so my HTML code will look like this:
Now I end up with 2 blocks with the same ID. If I make changes to the second block, they are not reflected on the front-end, I guess because the 2 blocks share the same ID. So if I wanted to duplicate a block like this, can I just update the ID with anything I like (as long as I know it is unique)?
So for example: will this work, without any additional complications?
The text was updated successfully, but these errors were encountered: