Template Part Block: Use get_block_file_template for rendering#52892
Conversation
get_block_file_template for rendering
|
The new function doesn't seem to |
I just did, and it seemed to work fine in my testing. (I made a quick child theme of TT3 locally and verified that it picked up the parent's template parts; I then added a modified I don't quite see why |
|
Since this PR has approval and parent themes seem to be working fine for me, I'll go ahead and merge (in order to unblock #51449). Happy to tweak or revert in case we find that it's breaking something after all! |
|
This introduced a regression: #56013 |
What?
Change the Template Part block's render method (
render_block_core_template_part) to useget_block_file_templaterather than a number of lower-level functions.Why?
Higher-level functions such as
get_block_file_templateapply filters (such as the eponymousget_block_file_template) that otherwise aren't invoked. (This is relevant e.g. for #51449.)Furthermore, it can be argued that if a high-level function is available to what otherwise requires calling a number of lower-level functions, it's preferable to use the high-level function (unless there are side effects and/or performance issues, of course) 😄
How?
By using
get_block_file_template(which returns aWP_Block_Templateobject) in the code branch that loads a block template from a theme file, thus supplanting calls to the lower-level_get_block_template_fileand_inject_theme_attribute_in_block_template_contentfunctions.Note that
get_block_file_templateinvokes both of them in its function body. (_inject_theme_attribute_in_block_template_contentis called via_build_block_template_result_from_file).Testing Instructions
Verify that Template Parts still work as before: