Archived topic
Content Templates: unwanted inheritance of properties
13 replies · Started by Gerald on February 22, 2022
I have set up three content templates for the blog page and archives, closely following Leo's fascinating demonstration video (https://www.youtube.com/watch?v=8byA37OTBRg). However, odd things are happening - the templates have become interlinked in a way I don't understand. Please help me understand what I'm doing wrong.
I am using GeneratePress Premium and GenerateBlocks Pro. The latest versions are installed.
All three content templates are built exclusively with GenerateBlocks elements.
- Template 1: Base template for all blog posts. It's made of: GB Containers, GB Buttons, GB Headlines, Dynamic Text
- Template 2: Template for a specific category. It's made of: GB Containers, GB Buttons, GB Headlines
- Template 3: Template for a different category. It's made of: GB Containers, GB Buttons, a GB Headline
Template 1 has been set as the Parent Element for the other two templates. Templates 2 and 3 have the same display order (0).
Now we get to the good part.
- I publish Template 1 and everything looks as it should.
- I publish Template 2.
- Suddenly Template 1 posts show up with Template 2 styles. GB Buttons in Template 1 appear with the styling from Template 2. The GB Headline suddenly gains the extra padding added for Template 2. Border values go missing.
- When I publish Template 3, things get even more unpredictable. Posts which should be styled by Templates 1 or Template 2 appear with a weird form of Template 3 styling. Template 1 items no longer display dynamic text, because Template 3 does not include a dynamic text block. Changing the display order does not mitigate the issue. At one point, my fiddling around eventually led to all posts showing up twice.
As a last resort measure, I have now unpublished Templates 2 and 3, but that's not really what I wanted.
I rebuilt all three templates, with identical results. Either I'm making the same error over and over or I have run into a GP/GB problem. Please help.
Hi there,
did you copy and paste the blocks from one template to another ? Or use a plugin to duplicate the elements ?
Hi David,
yes, I have copied and pasted blocks from one template to another. (I had actually done this because I'd seen it being done in your tutorials.)
The first time around, I did use a plugin to duplicate the post (which I also saw in one of your tutorials *g*), but I didn't do that the second time around, because I thought that could be the source of the problem. Same results, though.
Copying and Pasting between block elements will result in duplicate CSS classes including the unique CSS Class that GB uses. So you will need to rebuild those elements.
If you want to Copy and Paste, and avoid the duplicate classes, then first Duplicate the block(s) this duplicate will auto regenerate the unique classes, now you can cut/copy the duplicate.
I was afraid you would say that (I half-guessed that this would be the answer when I read your follow-up questions).
The idea to duplicate the block, then move it, is a cumbersome, but viable solution.
If I duplicate a group or a container block with all of its contents, will its contents also be assigned new classes?
(If you wish, I will later provide you with links to the GP videos I mentioned in parentheses. You might want to add a caveat to those, so others don't end up in the same mess ...)
If I duplicate a group or a container block with all of its contents, will its contents also be assigned new classes?
Yes - duplicating a Group or Container will update all the classes of the nested blocks.
(If you wish, I will later provide you with links to the GP videos I mentioned in parentheses. You might want to add a caveat to those, so others don’t end up in the same mess …)
Hoping that a fix comes through with the editor so we the copy and paste works like intended ... but thank you for the offer.
Thank you for confirming this!
Hoping that a fix comes through with the editor so we the copy and paste works like intended … but thank you for the offer.
So what I ran into is effectively a Gutenberg bug?
Backstory.... when the block editor was first built, the development team dismissed the need for dynamically generated classes/IDs. Which meant developers had to implement their own methods, but one of the issues with the common method ( and the one GB uses ) is copy /pasting won't refresh the blocks IDs.
There are several open issues on Gutenberg github that propose to introduce a core method, and if/when they do we will look to adopt that. In the meantime we are looking at methods to overcome the copy/paste issue.
Thanks for the explanation! Yeah, I see how different priorities caused this problem.
I was thinking: If I select the main container block in my troublesome Content Templates, I should be able to duplicate it, generating new IDs.
Then I should be able to delete the original main container and everything should be fine™.
Do you think that would work? Does WP generate UIDs/GUIDs or will I risk further ID collisions?
Yeah - in theory that should work as duplicating rebuilds them.
Thanks! That will be much easier than recreating everything ... again. :)
Many thanks, David, you've taken five minutes to solve a problem that caused me hours of headaches!
No problems - glad to be of help!
Duplicating the containers worked like a charm. Once again. Thanks, David!
For posterity, here's the workflow:
- Use the tree view to select the topmost container of each part of the element you want to duplicate
- Click on the three dot menu next to the container. Use the "duplicate" command.
- Delete the current container.
- Keep the duplicate.
When I did this, some color values reset themselves. That was a minor issue, though, and easily fixed.
The GeneratePress tutorial which suggested that I should either use "Copy all content" or to use a plugin for element duplication is "GeneratePress - Copy and Paste Content in the Block Editor" at https://www.youtube.com/watch?v=CsT1UOzZUgI
Awesome - thanks for sharing this.