Skip to content

Conditionally loading block templates classic themes #45341

@abaicus

Description

@abaicus

What problem does this address?

It is currently impossible to specify which templates should be loaded inside classic themes.

There are two theme supports to enable block templates and template parts:

add_theme_support( 'block-template-parts' );
add_theme_support( 'block-templates' );

A classic theme might implement a complex archive layout with many customization features but still want to allow the possibility to use a template for the archive based on a customizer setting.

I believe that this extends to block-based themes as well. If you want to define templates for CPTs (e.g., WooCommerce Single Product), these will be loaded automatically, regardless of the plugin’s state. When it comes to classic themes, authors would probably want to allow the user to pick which templates he intends to override with block templates.

I’ve seen that WooCommerce has managed to load templates from the plugin in a custom class, but that feels a bit cumbersome.

What is your proposed solution?

Allowing an arguments array with which templates to be loaded for both theme supports could be a good solution:

add_theme_support( 'block-templates',
	array(
		'index'      => get_template_directory() . '/includes/fse-templates/index.html',
		'front-page' => get_template_directory() . '/includes/fse-templates/front-page.html',
	)
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] ThemesQuestions or issues with incorporating or styling blocks in a theme.[Focus] Blocks AdoptionFor issues that directly impact the ability to adopt features of Gutenberg.[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions