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

Render wp:template-part in wp:pattern not working #37128

Open
BicanMarianValeriu opened this issue Dec 4, 2021 · 15 comments
Open

Render wp:template-part in wp:pattern not working #37128

BicanMarianValeriu opened this issue Dec 4, 2021 · 15 comments
Labels
[Block] Template Part Affects the Template Parts Block [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced Needs Technical Feedback Needs testing from a developer perspective. [Type] Bug An existing feature does not function as intended

Comments

@BicanMarianValeriu
Copy link

Description

While testing my custom theme and upcoming wp:pattern block I found that rendering wp:template-part in wp:pattern is not working giving a "Template part has been deleted or is unavailable: entry-meta" error even though the partial exists and it renders using normal query.

Everything is fine with normal query block but not working when calling the same query from a pattern.
See the bellow 4 images, 2 by 2, with working/bugged example.

I believe this is important to be fixed for WP5.9 launch.

Step-by-step reproduction instructions

  1. Create a query template, eg index.
  2. Use a template part in that query
  3. Create a pattern with that same query
  4. Call the patten instead of query blocks in the index
  5. Template-part will not be found to be rendered when wp:pattern is used.

Screenshots, screen recording, code snippet

image
image
image
image

Environment info

Both latest versions.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@annezazu annezazu added [Block] Template Part Affects the Template Parts Block [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced Needs Technical Feedback Needs testing from a developer perspective. labels Dec 15, 2021
@carolinan
Copy link
Contributor

carolinan commented Dec 15, 2021

I am able to reproduce this. I wonder if it is related to #36124

To test, I added this code to functions.php in Twenty Twenty Two:

register_block_pattern(
	'twentytwentytwo/test',
	array(
		'title'      => esc_html__( 'test', 'twentytwentytwo' ),
		'categories' => array( 'text' ),
		'blockTypes' => array( 'core/template-part' ),
		'content'    => '<!-- wp:template-part {"slug":"header","tagName":"header","style":{"spacing":{"padding":{"right":"var(--wp--custom--spacing--small, 1.25rem)","left":"var(--wp--custom--spacing--small, 1.25rem)"}}},"layout":{"inherit":true}} /-->',
	)
);

Note: Template parts are no longer allowed (they can't be placed) inside the post template.
See #37157

@carolinan
Copy link
Contributor

carolinan commented Dec 15, 2021

The template part is missing because the theme attribute is "undefined".
But can we safely assume that if the theme attribute is missing, it is always the active theme?
Right now we can't mix template parts between themes, but we "should" be able to do that in the future.

@carolinan
Copy link
Contributor

carolinan commented Dec 15, 2021

Perhaps it makes sense to fall back to a template part in the active theme, if no exact match is found?

@BicanMarianValeriu
Copy link
Author

I switched to wp:pattern inside wp:pattern until further updates - that works atm.

@carolinan carolinan changed the title Render wp:template-part in wp:pattern not working (important for WP 5.9) Render wp:template-part in wp:pattern not working Dec 15, 2021
@BicanMarianValeriu
Copy link
Author

BicanMarianValeriu commented Dec 15, 2021

@carolinan I can confirm that adding theme attribute ("theme":"wecodeart"), the block renders correctly - but you are right - it makes sense to fallback to the active theme if that is undefined.

Note: after #37370 I noticed that the "not found" message does not appear anymore, instead it renders the empty template-part container.

@annezazu
Copy link
Contributor

@ockham might you have any insights here?

@ockham
Copy link
Contributor

ockham commented Dec 17, 2021

I can have a look, but I'm not too familiar with the code that adds the theme attribute to template parts. AFAIR, @jeyip or @Addison-Stavlo might have more insight into this.

@ockham
Copy link
Contributor

ockham commented Dec 17, 2021

Perhaps it makes sense to fall back to a template part in the active theme, if no exact match is found?

This seems to make a lot of sense to resolve the current issue, but I believe there were some considerations around theme switches that lead us to introducing the theme attribute for template parts in the first place. In other words, if we fall back to the active theme, this might have some unwanted side effects, especially when a theme switch happens 😅

@carolinan
Copy link
Contributor

But if my existing theme has a template part called "header", and the new theme has a template part called "header", then wouldn't loading that second header template part be the expected result? Not an unwanted side effect.

@dashkevych
Copy link

It looks like this issue is still present in Version 6.1. While adding attribute "theme":"themename" helps to resolve the issue, it also causing same issue in when using a child theme.

@justintadlock
Copy link
Contributor

I'm working on a tutorial for the template-specific patterns and ran into this issue. Now that theme authors can register patterns for template types, this may increasingly become an issue because these types of patterns will often reference header/footer template parts.

But can we safely assume that if the theme attribute is missing, it is always the active theme?

This should be the expected behavior.

@justintadlock justintadlock added the [Type] Bug An existing feature does not function as intended label Apr 11, 2023
@annezazu
Copy link
Contributor

Related on that front when handling missing template parts: #49331

@t-hamano
Copy link
Contributor

This issue is similar to #55202 and may have already been resolved in the latest Gutenberg. Is there anyone else who can test it?

As shown below, the problem does not seem to occur, at least in TT4.

  • Access http://localhost:8888/?cat=1. This will reference the TT4 archive.html template.
  • Inside the archive.html template, we're calling a wp:pattern with a slug of posts-3-col.
  • In the posts-3-col pattern, we are calling a wp:template-part with a slug post-meta. In this issue, I think the problem is that this template part is not rendered correctly.
  • The post-meta template part directly references the wp:pattern with a slug hidden-post-meta.
  • On the front end, the pattern with a slug of hidden-post-meta seems to be rendering correctly.

As you can see, the template parts and patterns are nested in many layers, but they seem to be rendering correctly.

hidden-pot-meta

@strarsis
Copy link
Contributor

strarsis commented Jan 29, 2024

Am I (still) correct with the assumption that when specifying the theme for a template part, the template part is locked to a specific theme, but when omitting the theme field, a template part is used of same area (currently header or footer) is used from the active theme? The rationale behind this behavior is that when a theme is changed, the header and footer template parts are switched to the one offered by the new current theme, instead just breaking as not found.
However, when I strip the theme field from those template part elements, the editor is no longer able to find them. Is this a regression then?

@carolinan
Copy link
Contributor

@strarsis I did not understand the comment or question.
Both template parts, and templates are theme specific, even when the user creates them in the editor.
Is it a site specific pattern, a user created pattern, that is referencing a template part that is added by a theme and then breaking?
Can you share more information and step by step instructions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced Needs Technical Feedback Needs testing from a developer perspective. [Type] Bug An existing feature does not function as intended
Projects
Status: 💻 Needs development
Development

No branches or pull requests

8 participants