-
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
Add support for adding templates and template parts for plugins #42362
Comments
It isn't easy for a plugin to register a custom block template. I created a POC (I used Also, this is a production class that handles Block Templates for WooCommerce Blocks: As you can see, it is complex registering and handles custom block templates for a plugin. Also, the current POC is bugged because it doesn't load the custom block template from the database after the user saves a new version of the template. Following my exploration, it is necessary using three filters to register a block template:
Also, it is necessary to write custom logic to read the directory where the templates are placed and parse the filename to get the template's name. It would be great to have a better way/specific API to register block templates. |
I think this ticket may be a duplicate of #41401 I'm going to leave it open for now since it already has some valuable context here but want to make both sides aware of one another :) |
Just a heads-up that I left a comment with an API proposal in #41401 (comment).
+1 to closing this issue as duplicate of #41401, given that the other one is older. |
Closing to keep #41401 as the main source of truth |
What problem does this address?
Currently, templates are defined within the theme (source theme) and can be edited in the site editor (source custom). There are some use cases where plugins could also use the possibility to add a template. WooCommerce blocks plugin already adds templates for Product Catalog page, Product Page, etc. At MailPoet, we are considering using templates and templates parts for email templates.
WooCommerce Blocks developers documented how they added the templates. As you can see from the docs, adding a template is currently cumbersome.
What is your proposed solution?
This could be solved by adding an API for registering a template. I don't know the internals in detail, so I struggle with proposing the solution.
I was thinking about a function like:
or maybe just
The
$args
would cover parameters for defining the block template.It could be used for both templates and template_parts.
The text was updated successfully, but these errors were encountered: