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

gutenberg_locate_block_template slicing template slugs #37691

Open
shramee opened this issue Jan 3, 2022 · 0 comments
Open

gutenberg_locate_block_template slicing template slugs #37691

shramee opened this issue Jan 3, 2022 · 0 comments
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Needs Technical Feedback Needs testing from a developer perspective. [Type] Enhancement A suggestion for improvement.

Comments

@shramee
Copy link
Contributor

shramee commented Jan 3, 2022

Description

TLDR

Check if specificity $index of the located php $template is not false before clearing out the template candidates $templates in gutenberg_locate_block_template


Function gutenberg_locate_block_template trims $templates (template candidates) even when located php template doesn't match php candidates. This breaks template lookups for custom post types (product in my case) on lib/compat/wordpress-5.9/block-template.php:61.

The comment line says,

// If the template hiearchy algorithm has successfully located a PHP template file,
// we will only consider block templates with higher or equal specificity.

for product post type $template is ./wp-includes/template-canvas.php, which doesn't seem specific to me at all.

Possible Solution

Just check if the $index is not false before splicing the array.

Step-by-step reproduction instructions

  1. Create an FSE theme.
  2. Add single-product.html template.
  3. Notice it doesn't work.

Screenshots, screen recording, code snippet

image

Environment info

Gutenberg Version 12.2.0
WordPress Version 5.8.2

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

Yes

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

No

shramee added a commit to shramee/gutenberg that referenced this issue Jan 3, 2022
Check if specificity `$index` of the located php `$template` is not false before clearing out the template candidates `$templates` in `gutenberg_locate_block_template` function.
@annezazu annezazu added [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Needs Technical Feedback Needs testing from a developer perspective. labels Jan 3, 2022
@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Needs Technical Feedback Needs testing from a developer perspective. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants