-
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
Template Loader: Add theme block template resolution. #18247
Conversation
b2cc884
to
f11d41c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Co-Authored-By: Weston Ruter <[email protected]>
… in admin screens.
1f1431b
to
2cc7330
Compare
…rnmobile/gb-mobile-872-JSApplicationIllegalArgumentException-in-RCTAztecView * 'master' of https://github.com/WordPress/gutenberg: (56 commits) Update: Default gradients. (#18214) Fix: setting a preset color on pullquote default style makes the block invalid (#18194) Fix default featured image size (#15844) Fix postmeta radio regression. (#18183) Components: Switch screen-reader-text to VisuallyHidden (#18165) [rnmobile] Release 1.16.0 to master (#18261) Template Loader: Add theme block template resolution. (#18247) Add a README file for storybook directory (#18245) Add editor-gradient-presets to get_theme_support (#17841) Add "Image Title Attribute" as an editable attribute on the image block (#11070) enables horizontal movers in social blocks (#18234) [RNMobile] Add mobile Spacer component (#17896) Add experimental `ResponsiveBlockControl` component (#16790) Fix mover for floats. (#18230) Rename Component to WPComponent in docstring (#18226) Colors Selector: replace `Aa` text by SVG icon (#18222) Removed gif from README (#18200) makes the submenu items stacked vertically (#18221) Add block navigator to sidebar panel for nav block (#18202) Fix: consecutive updates may trigger a blocks reset (#18219) ...
// See if there is a theme block template with higher priority than the resolved template post. | ||
$higher_priority_block_template_path = null; | ||
$higher_priority_block_template_priority = PHP_INT_MAX; | ||
$block_template_files = glob( get_stylesheet_directory() . '/block-templates/*.html', 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need this to be in a separate folder? Can't we use the root folder? @mtias may have thoughts here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes it easier to resolve files and avoids potential future naming conflicts.
Is using this feature documented anywhere? https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/block-api/block-templates.md doesn't seem to mention it |
We just started to work on it: https://github.com/WordPress/gutenberg/pull/18890/files |
Follows #17512
cc @youknowriad @felixarntz @westonruter
Description
This PR follows the template loader work to support resolving theme block templates from a new
/block-templates
directory in themes.A theme block template is an HTML file named after the relevant template from the template hierarchy and it contains the serialized block content for the template.
The logic for resolving them is as follows:
After finding a suitable
wp_template
post for the current hierarchy, search for a higher priority match in the active theme's block templates and use it if found. If there is more than one, use the one with the highest priority.Note that it's "higher priority" and not "higher or equal priority". Between a
wp_template
post and a theme block template with the same priority, thewp_template
post should be preferred as it contains changes that the user explicitly persisted and that should live on across theme changes."Using it" means creating a temporary auto-draft so that the rest of the template loading logic works as expected and so that the user can eventually make changes and persist them in a
wp_template
post if they so desire.How has this been tested?
It was verified that
/block-templates
theme block templates are resolved as expected in the full site editing experiment.Types of Changes
New Feature: Themes can now register block templates for the dynamic template hierarchy.
Checklist: