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

FSE: Fall back to Top level PHP theme templates when no FSE templates are available #24834

Closed
tomjn opened this issue Aug 26, 2020 · 2 comments
Closed
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Priority] High Used to indicate top priority items that need quick attention

Comments

@tomjn
Copy link
Contributor

tomjn commented Aug 26, 2020

Currently template posts are used, falling back to block template files in the theme.

However, if neither exist, then no template is available. This also means that using full site editing requires a complete site rebuild.

In order to provide a fallback and migration path for non-block based themes, PHP templates should be added as a fallback for top level templates. This would mean files such as home.php, single.php, archive.php, etc would be loaded if no FSE equivalent is available. This does not apply to template partials however, e.g. get_template_part( 'foo', 'bar' ); would work the same as it always has in a PHP template, and no new functionality would be added to FSE block templates.

This also means that sites can convert their themes one template at a time, or conduct partial migrations without rebuilding an entire site from scratch.

Related to #24803

@tomjn tomjn changed the title FSE: Load Top level PHP theme templates when no FSE template is available FSE: Fall back to Top level PHP theme templates when no FSE templates are available Aug 26, 2020
@aristath aristath added [Feature] Full Site Editing [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Aug 27, 2020
@aristath
Copy link
Member

aristath commented Aug 27, 2020

I was thinking a bit about this one... The issue is that we need to check if a block-template exists before we hijack the query-template filter.
So I did a quick test by replacing the gutenberg_add_template_loader_filters function with this one:

function gutenberg_add_template_loader_filters() {
	foreach ( get_template_types() as $template_type ) {
		if ( 'embed' === $template_type ) { // Skip 'embed' for now because it is not a regular template type.
			continue;
		}

		$type = preg_replace( '|[^a-z0-9-]+|', '', str_replace( '-', '', $template_type ) );

		$template_override = gutenberg_override_query_template(
			'',
			str_replace( '-', '', $template_type ) . '_template',
			apply_filters( "{$type}_template_hierarchy", array( "{$type}.php" ) )
		);
		if ( $template_override ) {
			add_filter( str_replace( '-', '', $template_type ) . '_template', 'gutenberg_override_query_template', 20, 3 );
		}
	}
}

The above code works, so it should be possible to achieve what we want here by tweaking the logic of the above proof-of-concept to optimize it... We just need to discuss a bit and figure out where we want to hook and how to handle the conditional loading of FSE templates.

@aristath
Copy link
Member

This was done in #29026 and further refined in #31604

WordPress 5.9 Must-Haves automation moved this from 📥 To do to ✅ Done Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Priority] High Used to indicate top priority items that need quick attention
Projects
No open projects
Development

No branches or pull requests

3 participants