-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add Term Template block #70747
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
base: add/terms-query-block-container
Are you sure you want to change the base?
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: +975 B (+0.05%) Total Size: 1.89 MB
ℹ️ View Unchanged
|
Flaky tests detected in 1615969. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/16647389667
|
); | ||
|
||
const blockProps = useBlockProps( { | ||
className: clsx( 'wp-block-term-template' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What purpose does clsx
serve here?
$query = $query_block_context['termQuery']; | ||
|
||
$query_args = array( | ||
'per_page' => $query['perPage'] ?? 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these defaults the same as anywhere else in WordPress, or just ones you chose?
); | ||
} | ||
|
||
const MemoizedTermTemplateBlockPreview = memo( TermTemplateBlockPreview ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to add a comment explaining why we need the memo.
if ( isResolving ) { | ||
return ( | ||
<p { ...blockProps }> | ||
<Spinner /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Spinner
the best placeholder here? Could we use something that matches the format/layout of the block?
|
||
return ( | ||
<BlockContextProvider key={ term.id } value={ blockContext }> | ||
{ term.id === |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth extracting this condition to a function, so that it can have a name the explains more clearly what it's doing, especially as we do the same check lower down.
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth using the WordPress HTML API for this, rather than string manipulation?
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