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 has been deleted or is unavailable #44243

Closed
janboddez opened this issue Sep 18, 2022 · 21 comments
Closed

Template part has been deleted or is unavailable #44243

janboddez opened this issue Sep 18, 2022 · 21 comments
Labels
[Block] Template Part Affects the Template Parts Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.

Comments

@janboddez
Copy link
Contributor

Description

I've been working on a Twenty Twenty-Two child theme and it's been great.

I then tried to do the same (create a child theme) for Anders Norén's Björk, but the site's broken and the Editor shows a bunch of 'Template part has been deleted or is unavailable' errors.

debug.log shows errors like these:

[18-Sep-2022 15:27:33 UTC] REST request: /wp/v2/template-parts/bjork//sidebar: {"context":"edit","id":"bjork\/\/sidebar","_locale":"user"}(Header Present)
[18-Sep-2022 15:27:33 UTC] REST result: /wp/v2/template-parts/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+): {"code":"rest_template_not_found","message":"Er bestaan geen templates met dat id.","data":{"status":404}}(404) - [](User ID: 1)
[18-Sep-2022 15:27:33 UTC] REST request: /wp/v2/template-parts/bjork//footer: {"context":"edit","id":"bjork\/\/footer","_locale":"user"}(Header Present)
[18-Sep-2022 15:27:33 UTC] REST result: /wp/v2/template-parts/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+): {"code":"rest_template_not_found","message":"Er bestaan geen templates met dat id.","data":{"status":404}}(404) - [](User ID: 1)

Tried installing the Gutenberg plugin, but alas. (The TT2 child theme works great even without it.)

Found WordPress/create-block-theme#27 and https://core.trac.wordpress.org/ticket/54507 but they both seem solved, so I think something else might be going on.

Step-by-step reproduction instructions

Install Björk. Create (nearly) blank child theme. Like, just a style.css with the necessary information in it.

Activate it. Visit site, or Site Editor. You'll see missing block (part) templates.

Expect everything to just work as if the parent theme was active. As has been my experience with (a child theme of) TT2, luckily.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.0.2
  • Gutenberg: 14.1.0
  • Theme: Björk 0.1.6

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

@annezazu annezazu added [Status] Needs More Info Follow-up required in order to be actionable. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Block] Template Part Affects the Template Parts Block labels Sep 19, 2022
@annezazu
Copy link
Contributor

@MaggieCabrera any insight here based on your prior comments on a related issue?

Also, @janboddez thanks for opening! Can you confirm whether this happens with other block themes other than the Bjork one?

@janboddez
Copy link
Contributor Author

janboddez commented Sep 20, 2022

Tried another theme by the same author (Poe) and this time it seems to be only the "loop" block that's "unavailable."

Also tried with a child theme of Blockbase and that seems to work fine, for now (just had a quick glance at a few templates, nothing seemed off).

Did all of this on a different site than the first one, just in case.

So it might be a theme issue, but I don't see anything odd about how template parts are defined in theme.json. Also, the files are definitely there in the parent's parts folder (and work when the parent theme itself is active).

I also noticed that if I go and edit the Template Part itself, it's all there, as it should (even with the child theme active).

@annezazu
Copy link
Contributor

annezazu commented Sep 21, 2022

Hmm by chance, have you tried using this plugin to create a child theme instead? https://wordpress.org/plugins/create-block-theme/ Perhaps @jffng has some insight here :)

@janboddez
Copy link
Contributor Author

Just did, same result.

@Drivingralle
Copy link

Just did, same result.

Can confirm @janboddez report. Used the plugin to create child theme and get same error with Björk.

@janboddez
Copy link
Contributor Author

TL;DR
The issue is with the theme(s), but maybe this could still be documented better?

Some details:

In the original theme's bjork/templates/front-page.html, there's references to three template parts:

<!-- wp:template-part {"slug":"header","tagName":"header","className":"site-header","layout":{"inherit":true}} /-->

The one above works OK.

These two, however, error out:

<!-- wp:template-part {"slug":"sidebar","theme":"bjork","tagName":"aside","className":"site-sidebar"} /-->
<!-- wp:template-part {"slug":"footer","theme":"bjork","tagName":"footer","className":"site-footer"} /-->

See how they explicitly mention "theme":"bjork"? Well, remove that bit, and everything works.

Found out by adding a couple debug statements to the template REST API endpoint. The first template part above (so without explicit mention of the parent theme) ends up getting an ID of bjorkchildtheme//front-page, which is found fine (bjorkchildtheme is my child theme's slug). The others result in IDs bjork//sidebar and bjork//footer which lead to an error.

@janboddez
Copy link
Contributor Author

janboddez commented Sep 26, 2022

Left a message on the WP.org support forum, too: https://wordpress.org/support/topic/child-theme-and-template-parts-issue/

Not closing the issue, yet, as it could still be caused by theme creation tooling or whatnot.

@andersnoren
Copy link

I fixed this in Björk (and in my other block themes) by removing "theme":"bjork" from the <!-- wp:template-part --/> options.

I couldn't find any documentation for the "theme":"{theme-slug}" option for <!-- wp:template-part --/>, so I'm not sure what its intended behavior is.

@janboddez
Copy link
Contributor Author

janboddez commented Sep 27, 2022

Cool!

I do agree that either WP should be more robust for this, or the documentation improved (or both).

@annezazu
Copy link
Contributor

cc @DaisyOlsen and @justintadlock on the documentation front!

@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Oct 14, 2022
@mandrasch
Copy link

mandrasch commented Dec 4, 2022

Experienced this as well with https://wordpress.org/themes/raft/ by themeislel, Template part has been deleted or is unavailable: header when I use a child theme.

Suggestion of @andersnoren to change

<!-- wp:template-part {"slug":"header","tagName":"header","theme":"raft"} /-->

to

<!-- wp:template-part {"slug":"header","tagName":"header"} /-->

in wp-content/themes/raft/templates/front-page.html solved this for the index page.

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Dec 5, 2022
@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Dec 21, 2022
@Thelmachido
Copy link

Thelmachido commented Mar 15, 2023

Hmm by chance, have you tried using this plugin to create a child theme instead? https://wordpress.org/plugins/create-block-theme/ Perhaps @jffng has some insight here :)

The issue was recently raised in forums for this plugin, and the issue was reported here @matiasbenedetto fixed this 🎊

@janboddez can you please check your site if child themes created with the Create Block Plugin are still returning the error?

The issue has been marked as stale and will likely close soon.

@Thelmachido Thelmachido added Stale and removed Stale labels Mar 15, 2023
@janboddez
Copy link
Contributor Author

Then there are (were?) two issues:

  • Themes exported with that plugin (used to?) sometimes contain spaces, which breaks them (when used on other sites)
  • Child themes of a theme with any theme property/slug in one or several of their templates break (or at least did when I filed this issue, I've since stopped trying to create block child themes anymore); fixed by removing all mentions of a theme property

@matiasbenedetto
Copy link
Contributor

matiasbenedetto commented Mar 15, 2023

I made some testing about the template-part loading and this is what I found. I could reproduce the issue (Template part has been deleted or is unavailable) ONLY when the template part is linked from a pattern. The problem can be reproduced in both stand-alone/parent themes, and child themes.

Option working as expected:

To avoid this problem you need to add the theme key in the template-parts linked from patterns to make it work. The theme key should contain the slug of the theme in case of stand-alone themes or the child theme slug in case of the child themes. Any other option (not including the theme key, or adding the parent slug when you are on a child theme) won't work and will throw the error: Template part has been deleted or is unavailable.

<!-- wp:template-part {"slug":"header","theme":"themeslug"} /-->

I'm not sure if this was designed to work like this but by doing that I was able to avoid the problem.

About this issue Create Block Theme Plugin

Exporting stand-alone/parent themes works as expected.
Exporting child themes can fail in some cases because we are using the parent theme slug in the template parts linked from patterns. We need to fix that. I created an issue to follow-up: WordPress/create-block-theme#275

Extra Info:

If the template part is linked from a template and not from a pattern it works seamlessly no matter if you add the theme key in the link or not.

<!-- wp:template-part {"slug":"header","theme":"themeslug"} /-->
<!-- wp:template-part {"slug":"header","theme":"childthemeslug"} /-->
<!-- wp:template-part {"slug":"header"} /-->

☝️ These 3 options are working as expected when you link a template-part from a template (not from a pattern).

Steps to reproduce the issue:

If you want to reproduce the error loading template-parts linked from a pattern you can do something like this:

  1. Create an empty template front-page.html
  2. Create an empty pattern blog.php
  3. Create a template part header.html and some blocks to it.
<!-- wp:paragraph -->
<p class="has-text-align-left">Hi I'm a paragraph</p>
<!-- /wp:paragraph -->
  1. Link the blog.php from the front-page.html template:
<!-- wp:pattern {"slug":"mytheme/blog"} /-->
  1. Link the header.html template part from the blog.phppattern.
<?php
/**
 * Title: Blog post list
 * Slug: mytheme/blog
 */
?>

<!-- wp:template-part {"slug":"header"} /-->

I tested using:

  • WordPress 6.1
  • Gutenberg 15.3.1

@Retrofitterdk
Copy link

Retrofitterdk commented Apr 18, 2023

As far as I can tell this issue is not specifically related to neither patterns nor the Create Block Theme plugin.

From my experience whenever you use the site editor to make changes to a parent theme it will add theme key/themeslug to the wp:template-part html-comment in parent theme templates, and this will in my experience break the child theme.

To recreate the issue in it’s simplest form I have tried with these steps.

  1. Use Create Block Theme plugin to create a blank parent theme.
  2. Activate parent theme
  3. Observe that the parent theme has created a index template with a link to a template-part without themeslug
    <!-- wp:template-part {"slug":"header","tagName":"header"} /-->
  4. Use Create Block Theme plugin to ’Create child of Parent’.
  5. Upload and activate child theme
  6. Observe that Create Block Theme plugin hasn’t created any template or template-parts in the child theme – only style.css and theme.json
  7. Observe that the child theme correctly loads templates and template-parts from the parent theme.
  8. Reactivate the parent theme
  9. Use the site editor to make a change in a template or template-part
  10. In the site editor open the index.html template in code editor-’mode’ and observe that the site editor has changed the template-part link to
    <!-- wp:template-part {"slug":"header","theme":"parent","tagName":"header"} /-->
  11. Use Create Block Theme plugin to ’Overwrite Parent’
  12. In a code editor observe that the index.html template in the parent theme is now changed, so it links to the template-part with
    <!-- wp:template-part {"slug":"header","theme":"parent","tagName":"header"} /-->
  13. Reactivate the child theme
  14. Observe that the child no longer loads the header template part from the parent theme
  15. Open the index.html template in the site editor and observe the error message ’Template part has been deleted or is unavailable’.
  16. In a code editor manually remove the theme key from the index.html template so the template-part link is restored to
    <!-- wp:template-part {"slug":"header","tagName":"header"} /-->
  17. Observe that the child now correctly loads the header template part from the parent theme

I tested using

  • WordPress 6.2
  • Create Block Theme 1.8.1

No other plugins installed

@ndiego ndiego removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label May 30, 2023
@priethor priethor removed the [Status] Needs More Info Follow-up required in order to be actionable. label Jun 30, 2023
@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Aug 30, 2023
@janboddez
Copy link
Contributor Author

janboddez commented Oct 13, 2023

Not sure what happened here; I purposely left out the theme attribute of all my pattern (or template) calls and it worked wonderfully for months. Yet when I checked the Site Editor just now, this issue’s back.

Edit: It may very well be due to the fact that my site seems to have upgraded to 6.4 beta 😅

@t-hamano
Copy link
Contributor

t-hamano commented Nov 26, 2023

I followed this comment and tested to see if the problem still occurs. This problem doesn't seem to reproduce in my environment, but how about your environment?

I tested using

  • WordPress 6.4.1 (without Gutenberg Plugin)
  • Create Block Theme 1.13.4
  1. Use Create Block Theme plugin to create a blank parent theme.
  2. Activate parent theme
  3. Observe that the parent theme has created a index template with a link to a template-part without themeslug
    <!-- wp:template-part {"slug":"header","tagName":"header"} /-->

The template part now had the parent theme's slug:

<!-- wp:template-part {"slug":"header", "theme": "parent", "tagName":"header"} /-->

  1. Use Create Block Theme plugin to ’Create child of Parent’.
  2. Upload and activate child theme
  3. Observe that Create Block Theme plugin hasn’t created any template or template-parts in the child theme – only style.css and theme.json
  4. Observe that the child theme correctly loads templates and template-parts from the parent theme.

Here, the theme slug was automatically changed to the child theme:

<!-- wp:template-part {"slug":"header", "theme": "child" "tagName":"header"} /-->

  1. Reactivate the parent theme
  2. Use the site editor to make a change in a template or template-part
  3. In the site editor open the index.html template in code editor-’mode’ and observe that the site editor has changed the template-part link to
    <!-- wp:template-part {"slug":"header","theme":"parent","tagName":"header"} /-->

Before updating the template, the theme slug had changed to that of the parent:

<!-- wp:template-part {"slug":"header", "theme": "parent", "tagName":"header"} /-->

  1. Use Create Block Theme plugin to ’Overwrite Parent’
  2. In a code editor observe that the index.html template in the parent theme is now changed, so it links to the template-part with
    <!-- wp:template-part {"slug":"header","theme":"parent","tagName":"header"} /-->
  1. Reactivate the child theme
  2. Observe that the child no longer loads the header template part from the parent theme
  3. Open the index.html template in the site editor and observe the error message ’Template part has been deleted or is unavailable’.

Here the theme slug was automatically updated to that of the child theme and no error occurred:

<!-- wp:template-part {"slug":"header","tagName":"header","theme":"child"} /-->

  1. In a code editor manually remove the theme key from the index.html template so the template-part link is restored to
    <!-- wp:template-part {"slug":"header","tagName":"header"} /-->
  2. Observe that the child now correctly loads the header template part from the parent theme

Here I got the opposite result. If the theme slug was missing, a "Template part has been deleted or is unavailable: header" error occurred. However, this step should not be necessary since the expected results are obtained up to step 15.

eliot-akira added a commit to TangibleInc/template-system that referenced this issue Jan 29, 2024
eliot-akira added a commit to TangibleInc/empty-block-theme that referenced this issue Jan 30, 2024
@t-hamano
Copy link
Contributor

t-hamano commented Mar 1, 2024

I tested it again on WP6.5 Beta3, and the results are exactly the same as this comment, and the problem appears to be completely resolved.

I'd like to close this issue, but if I've missed anything, please feel free to comment.

@t-hamano t-hamano closed this as completed Mar 1, 2024
@realthemes
Copy link

realthemes commented Sep 28, 2024

My custom block theme keeps inserting "theme":"my-theme-name" in the navigation template part:

<!-- wp:template-part {"slug":"rlt-navigation","theme":"my-theme-name","area":"header"} /-->

This results in the error: "Template part has been deleted or is unavailable."

I'm unsure about the steps required to avoid this issue. I also suspect the Create Block Theme plugin might not be working correctly. It generates a child theme using API version 3, whereas my parent theme uses API version 2. Additionally, it doesn't create the single.html template, which I expect it to generate.

PS in theme.json file of the parent theme I have this code:

"templateParts": [
	{
		"area": "header",
		"name": "rlt-navigation",
		"title": "RLT Navigation Template Part"
	}
],

in parts folder of parent theme I have this file rlt-navigation.html with this code:

<!-- wp:rlt-blocks/rlt-navigation {"className":"is-style-rlt-navigation-shadow"} /-->

When I create child theme with Create Block Theme plugin, this results in the error: "Template part has been deleted or is unavailable." on this block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests