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:
"No matching template found"."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:
Template code was empty 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):
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.
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.