-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Post Template: Ensure layout classnames are not attached to inner li elements #41827
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -82,17 +82,28 @@ function render_block_core_post_template( $attributes, $content, $block ) { | |||||||
$content = ''; | ||||||||
while ( $query->have_posts() ) { | ||||||||
$query->the_post(); | ||||||||
|
||||||||
// Get an instance of the current Post Template block. | ||||||||
$block_instance = $block->parsed_block; | ||||||||
|
||||||||
// Set the block name to one that does not correspond to an existing registered block. | ||||||||
// This ensures that for the inner instances of the Post Template block, we do not render any block supports. | ||||||||
$block_instance['blockName'] = 'core/null'; | ||||||||
|
||||||||
// Render the inner blocks of the Post Template block, with `dynamic` set to `false` to ensure that no wrapper markup is included. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is a good comment! Saves folks searching around for API docs. Would it be worth adding that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, good suggestion! Yes, I think because of how unusual this block is, the more explanatory text, the better, to hopefully make it a little easier for anyone making future changes. I'll tweak the wording a little later today 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Committed in c8e2814. Thanks! |
||||||||
$block_content = ( | ||||||||
new WP_Block( | ||||||||
$block->parsed_block, | ||||||||
$block_instance, | ||||||||
array( | ||||||||
'postType' => get_post_type(), | ||||||||
'postId' => get_the_ID(), | ||||||||
) | ||||||||
) | ||||||||
)->render( array( 'dynamic' => false ) ); | ||||||||
$post_classes = implode( ' ', get_post_class( 'wp-block-post' ) ); | ||||||||
$content .= '<li class="' . esc_attr( $post_classes ) . '">' . $block_content . '</li>'; | ||||||||
|
||||||||
// Wrap the render inner blocks in a `li` element with the appropriate post classes. | ||||||||
$post_classes = implode( ' ', get_post_class( 'wp-block-post' ) ); | ||||||||
$content .= '<li class="' . esc_attr( $post_classes ) . '">' . $block_content . '</li>'; | ||||||||
} | ||||||||
|
||||||||
wp_reset_postdata(); | ||||||||
|
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 would be the option for developers who would want block supports for
core/post-template
later?Render them somewhere in the render callback?
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.
The supports still get rendered on the outer wrapper (this function is called with
core/post-template
) so the block supportsareshould still apply there (I think!).I'm not too sure about how we'd handle styling for the inner wrapper to be honest — I think the best bet for pattern design would be to have a Group block as the first child of the inner wrapper, and then folks can use block supports there. I was almost wondering if we could use a group block instead of
core/null
, but that felt like going down a rabbithole that might be a bit broader in scope than solving the current bug 🤔Longer-term, I'd love for us to figure out how to reliably get block spacing and block supports working nicely for styling up different kinds of post template layouts, though!