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

Allow the new wp_register_block_template to register both wp_template and wp_template_part types #65861

Open
daviedR opened this issue Oct 3, 2024 · 2 comments
Labels
[Type] Enhancement A suggestion for improvement.

Comments

@daviedR
Copy link
Contributor

daviedR commented Oct 3, 2024

What problem does this address?

Hi, I just checked the new wp_register_block_template API (WP 6.7 beta) that allows custom plugins (and themes) to register block templates in PHP.

I noticed that the API only supports creating block templates (wp_template) as the type property is hardcoded in the registry (WP_Block_Templates_Registry).

In some cases, plugins might want to add block template parts (wp_template_part) in PHP. For example, the WooCommerce plugin adds a Mini Cart block template part. And this can't be done using the new wp_register_block_template API.

What is your proposed solution?

Allow the wp_register_block_template API to also register a block template part. Perhaps by defining the type property in the $args parameter.

Currently, the get_block_templates function in the core can return either wp_template or wp_template_part objects based on the specified template_type parameter. And the returned objects for both types have similar structures. So maybe we can use the wp_register_block_template API to also register wp_template or wp_template_part type, instead of creating a separate API for template parts (e.g. wp_register_block_template_part).


Also, I am curious why is it named wp_register_block_template instead of register_block_template?
We have similarly named APIs, like register_block_type, register_block_style, register_block_pattern, etc.

@daviedR daviedR added the [Type] Enhancement A suggestion for improvement. label Oct 3, 2024
@rudrakshi-gupta
Copy link
Contributor

Hi, I would like to work on this issue.

rudrakshi-gupta pushed a commit to rudrakshi-gupta/gutenberg that referenced this issue Oct 7, 2024
…plate part along with the default block template

Fix WordPress#65861
rudrakshi-gupta pushed a commit to rudrakshi-gupta/gutenberg that referenced this issue Oct 7, 2024
…plate part along with the default block template

- Correct the indentation of lines

Fix WordPress#65861
@youknowriad
Copy link
Contributor

Ideally, we want to try to make template parts, special block patterns. Read this for more details #62566 (comment)

In that sense, there's already a registration function for patterns. So solving what that link proposes would be another way to solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants