WordPress / gutenberg

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

FSE - Template meta information and post type support do not work #31704

Closed rufus87 closed 2 years ago

rufus87 commented 3 years ago

Description

Custom template configuration in experimental-theme.json file does not work neither in default themes nor in custom ones.

Step-by-step reproduction instructions

  1. Create my-custom-template.html file within current active theme's "block-templates" folder
  2. Add configuration from Code snippet part to active theme's experimental-theme.json file
  3. Go to admin panel and go to "Posts -> Add New"
  4. In the opened screen open "Template dropdown"

Expected behaviour

  1. Template dropdown should not contain above mentioned my-custom-template as an option because it should not be available for any post type but page.
  2. The template name must be read as The template title instead of my-custom-template based on experimental-theme.json file configuration

Actual behaviour

  1. Template is available in all post types: postTypes restriction does not work
  2. Template name is read as my-custom-template instead of The template title

Screenshots or screen recording (optional)

image image image

Code snippet (optional)

...
"customTemplates": [
    {
      "name": "my-custom-template",
      "title": "The template title",
      "postTypes": [
        "page"
      ]
    }
  ]
...

WordPress information

Device information

rufus87 commented 3 years ago

Hi there,

Many thanks for your feedback, however it is not visible here.

Seams like you did not understand the issue correctly. The template appears in "Templates" dropdown in any post type, ie: "postTypes" restriction in experimental-theme.json file does not work. Right now "postTypes" is set to ['page'], but template is available for selecting in Templates dropdown when I try to add post - not page, as well as the template filename appears in dropdown instead of the configured title. There is no difference how template file is named, does it have page- prefix or not.

Thanks

Aljullu commented 3 years ago

I can reproduce this as well. For example, if I create a single-product.html template and then I add:

"customTemplates": [
    {
        "name": "single-product",
        "title": "Product page",
        "postTypes": [
            "product"
        ]
    }
]

to my theme.json, the single-product template is still available in pages and posts. Also, the title property is ignored and the template is listed as single-product instead of Product page.

It seems to be related to this TODO comment in the code:

https://github.com/WordPress/gutenberg/blob/9d382e4d7f8b1afba2e29fb66e98b95d5ba09c7a/lib/full-site-editing/page-templates.php#L21

I think this was regressed in #30438, specifically in these changes: https://github.com/WordPress/gutenberg/commit/7c134eb66f1e5ed67db646e19234d9edf6e3090e#diff-603069a6df3015f09478e5ed97c90a404f2e17fb29dc7af5467dac8131acc1c6. cc @youknowriad for awareness and in case you think this is something that needs to be prioritized.

Mamaduka commented 3 years ago

Created PR that should fix the customTemplates title issue - #35592.

I'm working on excluding templates based on "postTypes" PR should be ready shortly.