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

Try: extract template metadata from the HTML files directly #38984

Closed
wants to merge 1 commit into from

Conversation

oandregal
Copy link
Member

Spin-off from #36751

The templates & parts of block themes are declared via .html files. The metadata for each of those files (translatable title, area, post types, etc) is provided via an external file, the theme.json (see customTemplates and templateParts keys). This PR explores pulling metadata directly from the .html files, spinning off from #36751

Each template & part would add a top-level comment such as:

<!--
	title: Title for the template or part
	area: related-area
-->

How to test

  • Use the empty theme and WordPress 5.8.
  • Add the following to the parts/header.html file in the theme directory:
<!--
	title: Cabeceira
	area: header
-->
  • Go to the site editor and verify that the part name is now "Cabeceira". In trunk, it'd be "header".

TODO and related work.

  • In wp-cli: implement extracting the fields available for translation from the .html templates.
  • Fallback to the existing theme.json mechanism if no metadata was found in the template & part.
  • Make it work for 5.9 (provide plugin overrides to the core functions, etc).

@oandregal
Copy link
Member Author

cc @mcsf @mtias @youknowriad is this worth exploring further?

@oandregal oandregal added the [Feature] Templates API Related to API powering block template functionality in the Site Editor label Feb 22, 2022
@@ -323,7 +323,18 @@ function _get_block_templates_files( $template_type ) {
);

if ( 'wp_template_part' === $template_type ) {
$template_files[] = _add_block_template_part_area_info( $new_template_item );
$default_headers = array(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before looking at implementation, I'd like to confirm direction. This is just a way to make this work for testing.

@mtias
Copy link
Member

mtias commented Feb 26, 2022

Yes, I think this is worth exploring in the broad context of clarifying and improving the folder structure and auto-load mechanisms (patterns, templates, styles). theme.json feels ill-suited to be registering files.

@oandregal
Copy link
Member Author

Status: #47212 discovered an issue that was partially solved by #48129 The remaining work for this approach to be viable is tracked at #48408

@oandregal oandregal closed this Apr 19, 2024
@oandregal oandregal deleted the try/html-template-metadata branch April 19, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants