Gutenberg: Empty templates in Block Based Themes result in "No matching template found" message.

Created on 12 Feb 2020  路  12Comments  路  Source: WordPress/gutenberg

I've gone back and forth on whether to report this as a bug or not, but I found it confusing enough that I think it is a bug.

Describe the bug
A block template with no content in it results in an error message stating "No matching template found", even though a template was found, it was just empty.

To reproduce
Steps to reproduce the behavior:

  1. Under "Appearance" > "Templates", create a template with the slug "single-post", but put no content in it.
  2. Create and view a blog post.
  3. Notice you see the error "No matching template found".
  4. Now, add a file called "single.html" to your Block Based Theme, fill it with block content, and save it.
  5. View the blog post again, and notice you still see "No matching template found".

Seeing the message "No matching template found". was pretty confusing because I had multiple templates that existed, both of which would normally have worked in the old-style themes.

From a user perspective, I was just clicking around to try and learn this new system, and came to the conclusion that my theme was broken. But in reality, I had just added a user-created Block Template (in wp-admin) but put nothing in it yet.

I'm guessing there are still more plans for that error message, but just wanted to make a note that this type of thing will likely confuse both users and theme authors alike.

Expected behavior
There are a few possibilities for my expectations of the behavior:

If a template exists, but is simply empty, then do one of these:

  • Output Template code was empty
  • Output an actual empty page, matching the empty template.
  • Fall-back to the next-in-line template and use it (like single-post to single)

If a template truly does not exist at all (not just empty), and there's no fallback available either, then it might make sense to output "No matching template found", though any theme with an index.html file should be able to completely avoid this.

Desktop (please complete the following information):

  • OS: MacOS Catalina
  • Browser Chrome
  • Version 79.0.3945.130 (Official Build) (64-bit)

Additional context
This discrepancy is caused by the falsey check done here:
https://github.com/WordPress/gutenberg/blob/master/lib/template-loader.php#L230

I don't feel a falsey check on the value of post_content is really enough to determine whether a template exists or not, at least not enough to provide valuable/actionable feedback to the user.

To re-iterate my thoughts. I feel that either that should be changed to allow an empty template, use the next-in-line template available, or the error message should be adjusted based on whether a template exists, but is simply empty.

[Feature] Full Site Editing [Status] In Progress [Type] Bug

All 12 comments

cc @epiqueras

Output Template code was empty

I think this makes the most sense. Or do you think there is a use case for supporting empty templates? It seems more like mistakes users could make.

I'd probably opt for this personally Output an actual empty page, matching the empty template. as it's the most accurate even if weird. Maybe there's some hooks/filters to make use empty templates 馃し鈥嶁檪

I think that will confuse people, and I don't see a use-case for empty templates. All of the hooks/filters would have already run by that point.

If you create an empty php template today, it's shown right. That seems consistent and expected for me.

Devs only handle those; users also use block templates.

I don't think regular users will handle block templates from scratch, they could potentially edit existing templates but in general, the users creating the templates will have dedicated roles and capabilities.

They will create them from the UIs.

I can understand both points of view for sure.

I feel like an empty page is the most accurate, even if it is weird. But if paired with a block template indicator as proposed in https://github.com/WordPress/gutenberg/issues/20252, it might help to alleviate some of that user confusion.

Agreed, we can show an empty page once something like that is implemented.

@epiqueras Should I open another issue for this to make it show an empty page once #20252 is implemented?

Yes please, or add it to #20252.

Was this page helpful?
0 / 5 - 0 ratings