Template Loader: Add theme block template resolution.#18247
Merged
Template Loader: Add theme block template resolution.#18247
Conversation
westonruter
reviewed
Nov 3, 2019
westonruter
reviewed
Nov 3, 2019
westonruter
reviewed
Nov 3, 2019
westonruter
reviewed
Nov 3, 2019
b2cc884 to
f11d41c
Compare
Co-Authored-By: Weston Ruter <westonruter@google.com>
… in admin screens.
1f1431b to
2cc7330
Compare
4 tasks
daniloercoli
added a commit
that referenced
this pull request
Nov 5, 2019
…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) ...
youknowriad
reviewed
Nov 11, 2019
| // 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 ); |
Contributor
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
It makes it easier to resolve files and avoids potential future naming conflicts.
6 tasks
|
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 |
Contributor
Author
|
We just started to work on it: https://github.com/WordPress/gutenberg/pull/18890/files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #17512
cc @youknowriad @felixarntz @westonruter
Description
This PR follows the template loader work to support resolving theme block templates from a new
/block-templatesdirectory 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_templatepost 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_templatepost and a theme block template with the same priority, thewp_templatepost 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_templatepost if they so desire.How has this been tested?
It was verified that
/block-templatestheme 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: