WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.47k stars 4.18k forks source link

Patterns: Use patterns from the directory in the pattern block. #47880

Open scruffian opened 1 year ago

scruffian commented 1 year ago

What problem does this address?

The pattern block loads patterns based on a slug: <!-- wp:pattern {"slug":"core/simple-header"} /-->

This works when the pattern is in the theme, but if the pattern comes from the directory it only works in the editor, not in the front end. To reproduce, add this to the header.html of your active theme:

<!-- wp:pattern {"slug":"core/simple-header"} /-->

Load the site editor - you'll see the pattern. Load the front end - the pattern is missing.

richtabor commented 1 year ago

Are you thinking it'd always pull from the directory, unless the parent template was edited?

scruffian commented 1 year ago

Yes exactly, the same way that the block works for theme patterns. I think this could be powerful for themes as it means they can assemble a whole from the pattern directory very easily, and if the patterns need updating they will get the updates without doing anything.

Simple themes could just be a collection of patterns and styles with no need for custom templates.

richtabor commented 1 year ago

I think this could be powerful for themes as it means they can assemble a whole from the pattern directory very easily, and if the patterns need updating they will get the updates without doing anything.

I lean towards an inserted/template-applied pattern being locked to the theme/site—not editable from the Pattern Directory. It may introduce more issues than its worth (patterns updates that disrupt the site). I'm also not sure if this functionality would be used much. Maybe for headers, but most other patterns would be manipulated before publishing imo.

scruffian commented 1 year ago

My main thought was for headers, footers and query patterns. It would be powerful to be able to create a whole site just by reusing patterns from the directory. The approach would also have some maintenance benefits - any updates done to the patterns in the directory would immediately benefit the theme.