Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Part Not Found for badly formed wp:template-part HTML comment #16

Closed
bobbingwide opened this issue Nov 3, 2020 · 3 comments
Closed
Assignees
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Nov 3, 2020

While developing the archive.html template file I encountered a problem where the Template Part Not Found message was displayed but there was no template name. The only attribute value passed to gutenberg_render_block_core_template_part() was tagName, with a value of div.

Analysis of the HTML comment that formed the wp:template-part block indicated that I was missing a comma between attributes.

<!-- wp:template-part {"slug":"footer-menu","theme":"fizzie" "className":"footer-menu"} /-->

It would be helpful if the error could be detected and a message produced.

@bobbingwide bobbingwide added the bug Something isn't working label Nov 3, 2020
@bobbingwide bobbingwide self-assigned this Nov 3, 2020
bobbingwide added a commit that referenced this issue Nov 10, 2020
bobbingwide added a commit that referenced this issue Nov 10, 2020
@bobbingwide
Copy link
Owner Author

Another form that doesn't work, and doesn't even produce a message, is when there's no space between the block name ( template-part ) and the left curly brace, or when the wrong character has been used. eg (.

<!-- wp:template-part{"slug":"footer-menu","theme":"fizzie" "className":"footer-menu"} /-->
<!-- wp:template-part ("slug":"footer-menu", "theme":"fizzie" "className":"footer-menu"} /-->

@bobbingwide
Copy link
Owner Author

bobbingwide commented Mar 26, 2021

There are many more ways to write an invalid block tag inside an HTML comment.
I've found a few more recently while developing SB.

Too many closing curly braces.

<!-- wp:template-part {"slug":"page-footer","theme":"sb","layout":{"inherit":true}},"tagName":"footer"} /-->

I had this problem with a template-part. The extra curly brace prevented any of the attributes being set.
This caused a Warning messag from template-part.php

Warning: Undefined array key "slug" in C:\apache\htdocs\wordpress\wp-content\themes\sb\includes\template-part.php on line 78

An end block slash where it shouldn't be

<!-- wp:query-loop {"className": "sb hero" } /-->

This one took me longer to find. See bobbingwide/sb#13

@bobbingwide
Copy link
Owner Author

I'm closing this as wontfix. Some of the badly formed template-part tags will be removed from the templates that used them. This should improve performance very slighty and may also help anyone reading the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant