Skip to content
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

Updated correct template part location when creating patterns on save #413

Closed
wants to merge 1 commit into from

Conversation

eirichmond
Copy link
Contributor

When editing templates and including media when you "Save Changes" the block is converted to a pattern, the template part references are then included in the pattern in a directory /patterns/ this breaks the template part references.

This fixes the header and footer reference, moving it back to the template from the pattern.

@eirichmond eirichmond changed the title updated correct template location when creating patterns on save Updated correct template part location when creating patterns on save Jul 10, 2023
@pbking
Copy link
Contributor

pbking commented Jul 11, 2023

Thank you for this @eirichmond! This is a topic I've been struggling with for a while.

This is definitely something that I've manually had to do for a few themes. Template Parts referenced from Patterns (for various reasons) continues to be something we're struggling to work around.

Unfortunately, while this change you're introducing works for MOST themes I've recently come across some where this would not work. The most obvious example I've seen is where the header template is not the first thing in the page template but is instead embedded in a column block or nested in some other way. I don't believe this change would work for that scenario. I believe we can't assume the structure of the template, even though 'header is first, footer is last' is definitely the most commonplace.

@eirichmond
Copy link
Contributor Author

@pbking I completely understand what you mean, and I actually had a similar thought after I created this pull request.

I was thinking that perhaps, before creating the patterns and templates, we could generate a temporary unique string reference in the pattern and store it as the index in an array. This way, we can keep track of where the template parts should logically be placed and reference them from that array to ensure that the template parts and patterns are outputted in the correct order within the templates themselves.

However, it's just an idea that came to me later, and I haven't figured out yet how it would work in the code. I can visualise it in my head, but I need to dive deeper into it. If I can figure out a solution, I'll definitely update this pull request.

@pbking
Copy link
Contributor

pbking commented Jul 31, 2023

This was a good idea (I had a very similar one) but ultimately I think the correct fix here is to

  1. ensure that patterns are created without references to template parts
  2. change gutenberg to allow patterns to reference template parts without assigning a 'theme' attribute. I opened a Gutenberg issue to hopefully address that.

I'm going to close this item.

@pbking pbking closed this Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants