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

Feature: Allow Post Template block to get deeply nested within Query Block #67657

Conversation

fabiankaegy
Copy link
Member

What?

Allow the "Post Template" block to get nested deeply inside the "Query" block.

Why?

Especially now with the advent of region-based routing in the interactivity API we need to be able to place more other controls into the "Query" block so they can talk to the correct region router. This means if we built a custom filtering sidebar for example we need to place that query filter block into the query itself.

In order to actually be able to create rich layouts in these cases we also need to be able to move the actual list of posts around and nest it in a columns block for example.

Moving from parent to ancestor allows just that.

The "Post Template" block actually is the block that renders the ul element containing all the posts. So, moving this into a column still has 100% valid markup.

I've been running this on a few projects by manually overriding the parent to ancestor via the block_type_metadata filter.

Interestingly enough the Core TwentyTwentyFive theme even ships patterns that force this deeply nested structure in patterns.

https://github.com/WordPress/wordpress-develop/blob/8eb8d634095e9b6716e977abd1085bab8d703e6f/src/wp-content/themes/twentytwentyfive/patterns/template-query-loop-photo-blog.php#L30-L32

This would not be possible in the UI today but this PR will enable it.

How?

Changing parent to ancestor in the block.json

Testing Instructions

  1. Add a query loop
  2. Add a columns block inside the query loop
  3. Move the Post Template into one of the columns
  4. See that it works as intended in the editor and on the frontend

@fabiankaegy fabiankaegy added [Type] Enhancement A suggestion for improvement. [Block] Query Loop Affects the Query Loop Block [Block] Post Template Affects the Post Template Block labels Dec 5, 2024
@fabiankaegy fabiankaegy self-assigned this Dec 5, 2024
@youknowriad
Copy link
Contributor

That makes sense to me. It feels like an oversight. Any context @ntsekouras maybe

Copy link

github-actions bot commented Dec 5, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: fabiankaegy <[email protected]>
Co-authored-by: carolinan <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: Mamaduka <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka
Copy link
Member

Mamaduka commented Dec 5, 2024

The ancestor is a relatively recent addition to the schema compared to the parent (#39894).

It looks like @ntsekouras also created a similar PR - #48348.

@fabiankaegy
Copy link
Member Author

Ahh great find @Mamaduka

Happy to move forward with that PR also if we want that instead 👍

@carolinan since already addressed the query-pagination in #58602

@carolinan
Copy link
Contributor

I understood about two words of the PR description, I would encourage
1 Opening an issue before submitting a PR
2 using a simpler language.

I still think this change should happen.

@fabiankaegy
Copy link
Member Author

Sorry @carolinan. You are right, I should have created an issue first.

I realize the way I described the use cases here was quite cumbersome.

The whole Interactivity API powered enhanced pagination makes it possible to build Custom blocks which talk to the Query block and therefore now support building complex search / filtering experiences. An example of this in Core can be found in #67289 where the Search block is getting hooked up to the query.

In order for these filter / search blocks to actually talk to the query block they need to be nested within the Query.

Because of this need to be nested we run into many design limitations since it is impossible today to nest the Post Template block inside any other blocks such as a group or columns block.

A common design pattern here is to have a sidebar that contains all the filters and then a content area next to it that contains the list of posts.

Switching from parent to ancestor fixes this by allowing us to nest the filters and the post template in columns:
Schema showing a query block with columns block nested within. The columns block contains two columns. The first one has a custom/filter block in it and the second one has the post-template block in it.

@carolinan
Copy link
Contributor

The PHP tests keeps failing 🤷‍♀️

@Mamaduka
Copy link
Member

Mamaduka commented Dec 6, 2024

@fabiankaegy, I think we can merge this and address the remaining blocks in #48348. @ntsekouras, what do you think?

@fabiankaegy fabiankaegy merged commit c20ad9f into trunk Dec 9, 2024
73 of 75 checks passed
@fabiankaegy fabiankaegy deleted the feature/allow-post-template-to-be-nested-deeply-inside-query-loop branch December 9, 2024 10:46
@github-actions github-actions bot added this to the Gutenberg 19.9 milestone Dec 9, 2024
@ntsekouras
Copy link
Contributor

@fabiankaegy, I think we can merge this and address the remaining blocks in #48348. @ntsekouras, what do you think?

Thank you! I rebased the old PR to update the No results block as well.

@fabiankaegy fabiankaegy added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Dec 9, 2024
yogeshbhutkar pushed a commit to yogeshbhutkar/gutenberg that referenced this pull request Dec 18, 2024
…Block (WordPress#67657)

Co-authored-by: fabiankaegy <[email protected]>
Co-authored-by: carolinan <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Template Affects the Post Template Block [Block] Query Loop Affects the Query Loop Block Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants