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: proposal for "download pattern" in context-menu for selection of blocks. #44187

Open Humanify-nl opened 2 years ago

Humanify-nl commented 2 years ago

What problem does this address?

Patterns use absolute src urls. Deploying a new FSE theme with patterns made on a localhost server requires a search-replace in the code to change the paths to the live domain. This is really inconvenient.

As most know, there is a challenge in reading relative URL's from a HTML template (see explorations here: #31815, and this #20966). But the patterns engine now runs on PHP. To my understanding, this is possible because we can now properly parse blocks from a php file.

This proposal looks for a solution to make pattern creation (1) easier, and (2) solve the 'absolute url' problem.

Creating a pattern is currently done by: "copy all code, paste it in a php file in /patterns, add a file header". How about we automate this step?

What is your proposed solution?

When a selection of blocks is selected, a "download pattern" option should appear in the context menu.

Pressing this button should:

Why?

Subsequent pro's:

annezazu commented 10 months ago

Noting this as related to the overall effort to improve pattern management: https://github.com/WordPress/create-block-theme/issues/287