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

Saving theme creates unnecessary patterns #562

Open
pshemek opened this issue Apr 12, 2024 · 1 comment
Open

Saving theme creates unnecessary patterns #562

pshemek opened this issue Apr 12, 2024 · 1 comment

Comments

@pshemek
Copy link

pshemek commented Apr 12, 2024

I encountered this problem working with the plugin version 2.0.2 and WooCommerce templates, but it may be more widespread.

What happens?

Originally, the taxonomy-product_cat.html template contains this snippet:

<!-- wp:query-no-results -->
<!-- wp:pattern {"slug":"woocommerce/no-products-found"} /-->
<!-- /wp:query-no-results -->

In the editor the pattern is visible as a paragraph block telling "No products were found matching your selection."

When I modify the template and save the theme to files, the whole template gets replaced with:

<!-- wp:pattern {"slug":"mytheme/taxonomy-product_cat"} /-->

and a new pattern is created in patterns/taxonomy-product_cat.php

This pattern contains:

<!-- wp:query-no-results -->
<!-- wp:paragraph -->
<p><?php echo __('No products were found matching your selection.', 'mytheme');?></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->

I also tried with a custom pattern:

/**
 * Title: no-products-found
 * Slug: mytheme/no-products-found
 * Categories: hidden
 * Inserter: no
 */
?>
<!-- wp:paragraph -->
<p><?php echo __('No products were found matching your selection.', 'mytheme');?></p>
<!-- /wp:paragraph -->

and it behaves the same as the WooCommerce one.

What should happen?

As I already have <!-- wp:pattern {"slug":"woocommerce/no-products-found"} /--> (or my custom pattern) which is dynamically translated, I want to keep it in a regular template taxonomy-product_cat.html after saving without getting that mostly redundant taxonomy-product_cat.php created.

May be related to

#533 Export creates new patterns by copying content from other patterns, without re-using them

@pbking
Copy link
Contributor

pbking commented Apr 15, 2024

The problem here is that once you edit the template there is (currently) no way to put those changes into the pattern you were originally using. There's no pattern management within the editor so as far as the editor is concerned the template has all new content and you aren't using the pattern any more.

More specifically the content from the pattern is stored in the "user modified" template and if it were exported without "localizing and moving that content to a pattern" in the save/export process then the pattern still wouldn't be used. The content of the pattern would just be in the template.

The solution for this is the ability to manage patterns within the editor... something we hope to be able to provide with Create Block Theme (until it's available in core) but I'm not sure exactly how to accomplish this yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants