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 block should not be available in the Post Editor inserter #30668

Closed
priethor opened this issue Apr 9, 2021 · 13 comments · Fixed by #37157
Closed

Template Part block should not be available in the Post Editor inserter #30668

priethor opened this issue Apr 9, 2021 · 13 comments · Fixed by #37157
Assignees
Labels
[Block] Template Part Affects the Template Parts Block [Feature] Inserter The main way to insert blocks using the + button in the editing interface Needs Dev Ready for, and needs developer efforts [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@priethor
Copy link
Contributor

priethor commented Apr 9, 2021

Description

As of 10.4-RC1, Template Part blocks can be added to the Post Editor in the same way reusable blocks can be added. However, template parts can only be created from the Site Editor.

This issue is related to #30669, which presents the opposite logic for reusable blocks. Original discussion in #30308

Step-by-step reproduction instructions

  1. Go to 'Site Editor'
  2. Select any block and click on "Make template part"
  3. Go to the Post Editor.
  4. Open the inserter and look for the recently created template part.

Expected behaviour

Template parts should only be available to insert in template editors.

Actual behaviour

Template parts can be inserted in posts or pages.

WordPress information

  • WordPress version: 5.7
  • Gutenberg version: 10.4-RC1
  • Are all plugins except Gutenberg deactivated? Yes
  • Theme used? TT1 Blocks
@priethor priethor added [Type] Bug An existing feature does not function as intended [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Block] Template Part Affects the Template Parts Block labels Apr 9, 2021
@carlomanf
Copy link

There is nothing on a strictly functional level that prevents a template part from working inside a post or page content. It's more a question of protocol, and while most would agree it's a good protocol to leave template parts out of post or page content, that should be left to site administrators to decide. Would there then be a filter or similar that could bring back template parts to the post inserter if someone wanted to do so?

@priethor
Copy link
Contributor Author

Thanks for chiming in! Adding a filter is an interesting approach, although I'm wondering what could be a benefit of adding template parts to posts and pages rather than using reusable blocks, as the latter can be created directly from the post editor, are meant to contain content, and belong to the post context. Template parts are created from the site editor and template editors, more geared towards defining the structure and layout of the site itself rather than the content, and are not semantically meant to be added to the posts themselves (to post templates yes).

Could you provide any use-case that would benefit from using template parts rather than reusable blocks, if you happen to have one in mind? I can't seem to come up with one myself.

@carlomanf
Copy link

To clarify, I'm not envisioning an ad-hoc filter specifically for this block, but some kind of universal system that controls the block inserter for the different contexts.

There have been many cases where it's been deemed that a given block should only appear in the inserter in certain context(s). This could be within another block (e.g. Column only inside Columns), or it could be only in certain editors, or it could be only in certain post types, or it could be only for certain user capabilities, or it could be the negation/conjunction/disjunction of any of the above.

In this case, I assume you're talking about restricting this block to only be available for a particular post type (i.e. wp_template) but it's the same kind of idea as Column only being available inside Columns, for instance.

However, it seems that there has not been a consistent approach to the implementing restrictions like these. In some cases, it's been done by de-registering the entire block type. In other cases, it's been done by just hiding it from the inserter but allowing the block to be added using code view.

Would it not make sense to do all of this through a centralised system, to increase consistency while also allowing site administrators to modify the configuration through a filter if they want to? It would also make it trivial to solve this issue, rather than spend days discussing the best way to implement it.

@youknowriad
Copy link
Contributor

Template part block is not part of 5.8, that said, we still need a long term solution for this. I'm removing this from the 5.8 board.

@priethor priethor added the [Priority] High Used to indicate top priority items that need quick attention label Nov 17, 2021
@noisysocks noisysocks added the Needs Dev Ready for, and needs developer efforts label Nov 21, 2021
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Nov 24, 2021
@ntsekouras ntsekouras removed the Needs Dev Ready for, and needs developer efforts label Nov 24, 2021
@ntsekouras ntsekouras removed their assignment Nov 25, 2021
@noisysocks noisysocks added Needs Dev Ready for, and needs developer efforts and removed [Status] In Progress Tracking issues with work in progress labels Dec 1, 2021
@noisysocks
Copy link
Member

Adding Needs Dev back to this as #36810 did not work out. It'd be appreciated if a dev can pick this up and explore alternative approaches to fixing this for WP 5.9. Perhaps the one mentioned by @gziolo in #36810 (comment).

@adamziel
Copy link
Contributor

adamziel commented Dec 2, 2021

To me, a block is self-contained and don't need to understand how all the different editors work. I explored using filters to make the editor modify block supports as it needs in #37065.

@noisysocks
Copy link
Member

@adamziel: Just confirming, is #37157 the current PR folks ought to review in order to action this issue?

@youknowriad
Copy link
Contributor

@noisysocks yes, for me.

@johnstonphilip
Copy link
Contributor

Could you provide any use-case that would benefit from using template parts rather than reusable blocks, if you happen to have one in mind? I can't seem to come up with one myself.

@priethor One potentially interesting use case: the Block Pattern Directory.

If I want to create Block Patterns that can be easily dropped onto page.html, single.html, etc, right now I cannot because I can't use the the template part block.

@priethor
Copy link
Contributor Author

priethor commented May 3, 2022

Hi @johnstonphilip , thanks for the feedback.

Let me see if I understand the scenario. Would you like to create Block Patterns in the Post Editor and submit them to the directory? If so, is there currently any blocker to create those same patterns in the Site Editor instead, where the Template Part block is indeed available and given those patterns are meant to be used in templates like single.html, etc?

@johnstonphilip
Copy link
Contributor

@priethor Not completely. I would like to submit block patterns to the directory using the UI provided here:
https://wordpress.org/patterns/new-pattern/

Notice that it appears to be using the post editor, not the site editor, and therefore, the template part block is not available.
Screen Shot 2022-05-03 at 10 24 15 AM

According to the instructions here, this is the only way to submit patterns.

@priethor
Copy link
Contributor Author

priethor commented May 5, 2022

Thanks for the extra context! I think this is more of a limitation in the Pattern Creator rather than an issue with the Post Editor, so I've opened an issue in the Pattern Directory repository accordingly.

@bobbingwide
Copy link
Contributor

I was pointed to this issue from #core-editor when I asked "why, in the Post Editor, the block inserter doesn't display template parts but I can still paste them?"

In previous comments there were questions regarding a use case for using template parts versus reusable blocks.

Well, one answer is:

  1. That template parts can be written by theme creators.
  2. And in the future they can be localized into multiple locales.
  3. And that they are subtly different from patterns.

I used template parts in Dec 2020 to demonstrate my prototype for internationalizing and localizing a block based theme.
See #27402 or https://herbmiller.me/localization-of-full-site-editing-themes/

I don't particularly want to revert the change that was implemented for this issue but would like to point out that in the current implementation.

  1. Any template parts that are already in post content do continue to work.
  2. Template parts can be copied and pasted from one post to another, both using the Visual and Code editor.
<!-- wp:template-part {"slug":"i18n-test","theme":"fizzie"} /-->

And I look forward to this continuing to be the case.

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] Inserter The main way to insert blocks using the + button in the editing interface Needs Dev Ready for, and needs developer efforts [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
8 participants