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

Not all custom .html templates in the templates folder are editable from the Template section #37969

Closed carolinan closed 2 years ago

carolinan commented 2 years ago

Description

In a custom block theme, I have the following custom templates in the templates folder: no-title-template.html sidebar-page-template.html sidebar-post-template.html

I am using these longer names because I don't want them to be automatically assigned to a post called "sidebar" and so on.

In theme.json:

    "customTemplates": [
        {
            "name": "no-title-template",
            "title": "No title",
            "postTypes": [ "post","page" ]
        },
        {
            "name": "sidebar-page-template",
            "title": "Page with sidebar",
            "postTypes": [ "page" ]
        },
        {
            "name": "sidebar-post-template",
            "title": "Post with sidebar",
            "postTypes": [ "post" ]
        }

The no title template has an Edit link when it is selected in the Template section in the block editor. The other two do not have an edit link. (Changing the PostTypes to include both post and pages makes no difference)

What is the correct way to name the template files?

Step-by-step reproduction instructions

You can test this by installing a theme from the theme directory called "Aino", which has several templates.

  1. Activate the block theme
  2. Create a new post.
  3. In the Templates section, select the following templates in the select list: -Post with Portrait Featured image -the Edit link is available -Post without Comments -the Edit link is not available

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 5.9-RC2-52567 With and without Gutenberg current trunk Windows 10. Chrome.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

carolinan commented 2 years ago

Pinging @ellenbauer in case you want to test if you can reproduce this.

carolinan commented 2 years ago

Way over my head here, but it seems that the template is undefined, which leads to the missing edit link, when this condition is triggered: https://github.com/WordPress/gutenberg/blob/trunk/packages/edit-post/src/store/selectors.js#L399

carolinan commented 2 years ago

I can't explain this but if I delete the page.html AND search.html templates from the theme, sidebar-post-template.html has a visible and working edit link.