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

Template Loader: Add theme block template resolution. #18247

Merged
merged 5 commits into from Nov 4, 2019

Conversation

@epiqueras
Copy link
Contributor

epiqueras commented Nov 2, 2019

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, the wp_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:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
lib/template-loader.php Outdated Show resolved Hide resolved
lib/template-loader.php Outdated Show resolved Hide resolved
lib/template-loader.php Outdated Show resolved Hide resolved
lib/template-loader.php Outdated Show resolved Hide resolved
lib/template-loader.php Outdated Show resolved Hide resolved
lib/template-loader.php Outdated Show resolved Hide resolved
lib/template-loader.php Outdated Show resolved Hide resolved
@epiqueras epiqueras force-pushed the add/theme-block-template-resolution branch from b2cc884 to f11d41c Nov 3, 2019
Copy link
Member

felixarntz left a comment

👍

@epiqueras epiqueras force-pushed the add/theme-block-template-resolution branch from 1f1431b to 2cc7330 Nov 4, 2019
@epiqueras epiqueras merged commit 3d6392d into master Nov 4, 2019
1 of 2 checks passed
1 of 2 checks passed
pull-request-automation
Details
Travis CI - Pull Request Build Failed
Details
@epiqueras epiqueras added this to Done in Phase 2 via automation Nov 4, 2019
@epiqueras epiqueras deleted the add/theme-block-template-resolution branch Nov 4, 2019
@mmtr mmtr mentioned this pull request Nov 4, 2019
4 of 4 tasks complete
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)
  ...
// 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 );

This comment has been minimized.

Copy link
@youknowriad

youknowriad Nov 11, 2019

Contributor

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.

This comment has been minimized.

Copy link
@epiqueras

epiqueras Nov 11, 2019

Author Contributor

It makes it easier to resolve files and avoids potential future naming conflicts.

@youknowriad youknowriad modified the milestones: Future, Gutenberg 6.9 Nov 11, 2019
CreativeDive added a commit to CreativeDive/gutenberg that referenced this pull request Nov 12, 2019
* Template Loader: Add theme block template resolution.

* Apply suggestions from code review

Co-Authored-By: Weston Ruter <westonruter@google.com>

* Template Loader: Add missing `isset`.

* Template Loader: Only create auto-draft of block template for editing in admin screens.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.