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

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.

@epiqueras epiqueras added Framework Issues related to broader framework topics, especially as it relates to javascript Customization Issues related to Phase 2: Customization efforts [Feature] Full Site Editing labels Nov 2, 2019
@epiqueras epiqueras added this to the Future milestone Nov 2, 2019
@epiqueras epiqueras self-assigned this Nov 2, 2019
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 Compare November 3, 2019 18:21
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

👍

@epiqueras epiqueras force-pushed the add/theme-block-template-resolution branch from 1f1431b to 2cc7330 Compare November 4, 2019 00:29
@epiqueras epiqueras merged commit 3d6392d into master Nov 4, 2019
@epiqueras epiqueras added this to Done in Phase 2 via automation Nov 4, 2019
@epiqueras epiqueras deleted the add/theme-block-template-resolution branch November 4, 2019 00:55
@mmtr mmtr mentioned this pull request Nov 4, 2019
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)
  ...
// 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 );
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@drywall
Copy link

drywall commented Dec 4, 2019

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

@epiqueras
Copy link
Contributor Author

We just started to work on it: https://github.com/WordPress/gutenberg/pull/18890/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customization Issues related to Phase 2: Customization efforts Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
No open projects
Phase 2
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants