Add Term Template block#70747
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +1.5 kB (+0.08%) Total Size: 1.91 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 7d9b497. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/16678873993
|
| $query = $query_block_context['termQuery']; | ||
|
|
||
| $query_args = array( | ||
| 'per_page' => $query['perPage'] ?? 100, |
There was a problem hiding this comment.
Are these defaults the same as anywhere else in WordPress, or just ones you chose?
There was a problem hiding this comment.
At the moment, these are just values I've chosen that I thought made the most sense for this block.
For per_page, I don't think this has a default value. It could be set to the global option with get_option('posts_per_page'), or it might be worth adding a max number control immediately to the Terms Query block, and the control could have a reasonable default.
There was a problem hiding this comment.
The REST API generally has a per_page limit of 100. Not sure defaulting to the posts_per_page options makes sense as these aren't posts but I suppose it's something to fall back on.
There was a problem hiding this comment.
I didn't realise the REST API has that limit, I think 100 is a good default then. Thanks!
Yeah, I wasn't sure about using posts_per_page, especially as I think this value will often be lower than what most taxonomy queries may require, so it doesn't make much sense.
| if ( isResolving ) { | ||
| return ( | ||
| <p { ...blockProps }> | ||
| <Spinner /> |
There was a problem hiding this comment.
Is Spinner the best placeholder here? Could we use something that matches the format/layout of the block?
There was a problem hiding this comment.
Nice idea, thanks! I've added some grey placeholders in list items in 0f82d3b:
Screen.Recording.2025-08-01.at.12.40.53.mov
I've used a similar animation to what's currently used in the Navigation and LinkControl blocks. It might need some tweaking but I prefer this to the spinner.
| $children_content = render_block_core_term_template_hierarchical( $terms, $block, $term->term_id ); | ||
|
|
||
| if ( ! empty( $children_content ) ) { | ||
| $term_content = str_replace( '</li>', '<ul>' . $children_content . '</ul></li>', $term_content ); |
There was a problem hiding this comment.
Would it be worth using the WordPress HTML API for this, rather than string manipulation?
There was a problem hiding this comment.
This may be moot because filtering to only children of a specific term should happen at the query level.
There was a problem hiding this comment.
I don't think the HTML API can handle content replacement; I can't see a way to pass the content into the new processed HTML. But I'm not certain! Maybe there is a way to do this.
…-block # Conflicts: # packages/block-library/src/terms-query/terms-query-content.js
70a9e9a to
7d9b497
Compare
scruffian
left a comment
There was a problem hiding this comment.
This is looking good to me. Let's bring it in.
* Add term template block * Add experimental flag * Fix server sider rendering * Fix render_block_core_term_template * Update query to termQuery * Remove termType * Fix spacing * Remove showOnlyTopLevel * Fix linting * Create test fixtures * Remove editorStyle * Remove clsx * Add comment for memo * Add custom loading placeholder * Add isActiveTerm function * Handle children filtering on query level * Disable layout controls * Fix front end styling Co-authored-by: mikachan <mikachan@git.wordpress.org> Co-authored-by: cr0ybot <cr0ybot@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org> Co-authored-by: scruffian <scruffian@git.wordpress.org>
What?
Part of #49094.
This adds a new block called Term Template, to be used as an inner block in Terms Query. This can be tested as part of a larger PR at #70682.
Why?
To allow for more options and flexibility when displaying terms.
How?
This provides a template for each term to be displayed. For now, I've just rendered the term name in an
<li>so there is some basic content for testing. We should replace this with an inner block in a follow-up PR.Testing Instructions
Screenshots or screencast