0

It is possible to detect when the Inserter panel is opened. It can be done using the following code snippet:

wp.data.select( 'core/edit-post' ).isInserterOpened()

However, I am wondering if there is an event in wp.data that allows to detect if the user has selected a block pattern (via Patterns tab) from a specific category (for instance, the Query category).

Use case

I have a theme that has two templates: Default and Custom.

The Default template displays a page layout with the page title, content area and sidebar.

The Custom template displays a page layout with with content only.

Also, the theme has a special Pattern category named "Pages". This category contains pre-made page layouts.

By default, WordPress displays (sets) Default template as initial template of the page.

My goal is to detect when user selects a block pattern from "Pages" category, and change template from Default to Custom in the editor automatically.

2
  • what are you trying to do that requires this? Can you add any context? Note that once a pattern is used it becomes the blocks the pattern contains, the pattern itself doesn't exist in the content
    – Tom J Nowell
    Commented Apr 21, 2022 at 23:48
  • Thank you for a suggestion, Tom. I have added more context to my question.
    – user85513
    Commented Apr 22, 2022 at 0:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.