Skip to content

Saving theme creates unnecessary patterns #562

Open

Description

@pshemek

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

Activity

  1. pbking commented on Apr 15, 2024

    @pbking
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Patternsabout pattern managementbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions