Skip to content

Add support for adding templates and template parts for plugins #42362

@costasovo

Description

@costasovo

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:

/**
 * @param WP_Block_Template
 */
function register_block_template( WP_Block_Template $template ) {}

or maybe just

function register_block_template( array $args ) {}

The $args would cover parameters for defining the block template.

It could be used for both templates and template_parts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Technical FeedbackNeeds testing from a developer perspective.[Feature] ExtensibilityThe ability to extend blocks or the editing experience[Feature] Site EditorRelated to the overarching Site Editor (formerly "full site editing")[Feature] Templates APIRelated to API powering block template functionality in the Site Editor[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions