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

Can not insert/use Template Part block within Post Template block #57054

Open
webmandesign opened this issue Dec 14, 2023 · 7 comments
Open

Can not insert/use Template Part block within Post Template block #57054

webmandesign opened this issue Dec 14, 2023 · 7 comments
Labels
[Block] Post Template Affects the Post Template Block [Block] Template Part Affects the Template Parts Block Needs Technical Feedback Needs testing from a developer perspective. [Type] Bug An existing feature does not function as intended

Comments

@webmandesign
Copy link
Contributor

Description

In Site Editor it seems I can not insert a Template Part block into a Post Template block.

When I switch to code editor view and add the Template Part block code as a child of Post Template block, it works.
But in visual view I can not insert or drag the Template Part block into the Post Template block.

Step-by-step reproduction instructions

  1. Using Twenty Twenty Four theme and current WordPress 6.4.2, create a new template part for displaying a post in posts list (I simply used Group block with Fetured Image and Title block within for testing).
  2. Open "Index" template for editing in Site Editor.
  3. Try to replace the content of the Post Template block with Template Part that displays your newly created template part. It is not possible unless you do it writing block code in code view of Site Editor.

(Check our the attached video.)

Screenshots, screen recording, code snippet

template-part--post-template.mp4

The video shows Twenty Twenty Four theme, editing "Index" template in Site Editor and trying to add a Template Part block into Post Template block.

Environment info

  • WordPress 6.4.2
  • Gutenberg 17.2.1

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

@webmandesign webmandesign added the [Type] Bug An existing feature does not function as intended label Dec 14, 2023
@webmandesign
Copy link
Contributor Author

Also, you can see in the video that there already is a "Post Meta" Template Part block within a Stack within Post Template block. This is part of Twenty Twenty Four template code. Like I've mentioned, adding Template Part block with code works.

I've also tried to move the "Post Meta" Template Part block but once I tried to drag it onto a different place I could not reinsert it anywhere within Post Template block.

@webmandesign
Copy link
Contributor Author

Is there any code solution I can use to fix the issue in my theme?
(I am comfortable modifying blocks with JavaScript blocks.registerBlockType hook, so if there is a block.json option I can set either for Template Part or for Post Template block to make this work, it would be great.)

@t-hamano t-hamano added [Block] Template Part Affects the Template Parts Block [Block] Post Template Affects the Post Template Block labels Dec 14, 2023
@annezazu annezazu added the Needs Technical Feedback Needs testing from a developer perspective. label Dec 14, 2023
@annezazu
Copy link
Contributor

I tried to find the reason for this and couldn't quite pinpoint the answer looking through PRs but I wonder if it has to do with recursion prevention of some sort. @ntsekouras might you know?

@ntsekouras
Copy link
Contributor

It seems this is a conscious decision that was taken a long time ago though and could be revisited.

I'll also cc @talldan because I think there is some work unifying template parts with patterns, so it seems relevant.

@webmandesign
Copy link
Contributor Author

Thanks for the info. It would be really great if this was reconsidered as it causes confusion with users. Especially when theme adds these with code and user can't modify them visually in Site Editor.

@talldan
Copy link
Contributor

talldan commented Dec 19, 2023

Maybe the post-template restriction could be lifted? I'm not really sure I see an issue with it. If it's already used like this in Twenty Twenty Four, then that horse has already bolted!

A pattern would probably work fine for this use case as well if it's a user created template part.

For post content, I think that would probably be more challenging. Template parts like headers and footers might result in a semantically incorrect web page too easily. The permission models for editing template parts are also quite different, though I haven't looked too deeply into the implications of this. Ideally users wouldn't be able to edit them if they don't have permissions (the same issue has existed with patterns/reusable blocks for a while - #32353, but solutions are now being explored). So I think it would be too soon for adding template parts to post content.

@webmandesign
Copy link
Contributor Author

Agreed, there are potential issues regarding allowing Template Part within Post Content. Personally I haven't stumbled across the need for using Template Part in Post Content.

I'm only asking about allowing Template Part within Post Template as that's pretty common use in my themes and currently in Twenty Twenty Four too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Template Affects the Post Template Block [Block] Template Part Affects the Template Parts Block Needs Technical Feedback Needs testing from a developer perspective. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants