-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Template parts need to inherit the query context #28011
Comments
It seems that query context isn't passed into template parts(!). This means that query-pagination blocks must be in the same template file as the query block or they won't work. Related: WordPress/gutenberg#28011
I retested this today after James mentioned in 37749 that it was working. I was able to place template parts with working post blocks (author, content, post date, etc) inside the post template block. (WordPress 5.9 RC2, current Gutenberg trunk.) Pinging @ryelle @tellyworth in case you want to test it as well. |
It seems that query context isn't passed into template parts(!). This means that query-pagination blocks must be in the same template file as the query block or they won't work. Related: WordPress/gutenberg#28011
I think I may have found a bug related to this issue. I'm not sure if I should open a new one, so I'll describe it here. Please forgive me if it's the wrong place and if so, let me know it and I'll start a new one. I'm running WordPress 5.9 + Gutenberg 12.6.0 I'm developing a Blockbase child theme and I have a few CPTs. Although index and archive templates are identical, I need to keep them both as otherwise CPT pages will inherit the parent theme (Blockbase) archive template. So to make it easier to maintain it I created a template part out of the Post Template block. However, I tested it with Gutenberg on and off and it doesn't work as expected (I have some block plugins which I deactivated to run these tests too). The Query Loop block layout settings aren't applied in the site's frontend even though it does in the editor. It is set to display as a grid, but it renders as a list. I noticed that the container div doesn't have the flex and columns css classes. Maybe it's because it's inside a div.wp-block-template-part. Index Template code:
Rendered HTML:
|
@catkit What is inside the content template part? |
@carolinan this issue came up in today's Editor Bug Scrub. Is this still an issue? I am unable to add a Template Part block inside of the Post Template block, so perhaps something changed? Anyway, if still valid, I'll remove the "Stale" label. Thanks! |
The first sample code presented in this issue contains blocks ( @carolinan |
I retested with Gutenberg 14.0.2. The original issue where the blocks inside the template part showed content from the wrong block in the query has been fixed. Testing instructions:
It is not possible to place template parts inside the post template in the site editor. (And template parts can't be used in the block editor at all) Here is another example of where we can do something in the HTML, that is not causing block validation errors or warnings in the editor, but that can not be done in the editor: |
@carolinan |
Is your feature request related to a problem? Please describe.
In my theme I added a query with post excerpt, date, tags, categories and author.
But when I move the date, tags categories and author block to a template part and include this template part
in the loop, the context is lost and the information for the first post in the loop is repeated.
Describe the solution you'd like
I want to be able to reuse my template parts instead of repeating the same code in multiple places.
Example:
Main query:
Meta.html template part:
The text was updated successfully, but these errors were encountered: