-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Edit Post]: Hide Template part in post editor #36810
Conversation
Size Change: +258 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
It works so I guess it's fine to proceed for now. However in the long run we need a general API that removes the block from the inserter when you are in a given context – in this case that would be inside the Post Content block. There is also a related issue filed for further restricting inserting blocks to a given template types: #30679. |
I'm not sure the current PR hides the block when you're inside "post-content" block in the site editor. |
I can confirm that
✔️ template parts can still be added outside the post content block in the template editor What is the expected result if a block pattern includes a template part block? |
Did a quick test, in the block editor, the block pattern with template part inside is not available in the inserter. |
This PR hides the
You mean only outside the
Agreed. |
The post editor is basically the same thing as the post content block, because the content that is there is also the same content that is show in the post content block in the site editor or template editor. So my expectation is that if I'm not able to use the template part in the post editor, I shouldn't be able to use inside the post content block either. |
I tried a different approach with a new |
3b01241
to
9d68fa6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd appreciate more testing but I think the behavior now is the correct one.
I am unable to insert a template part in the post editor ✅ However I am able to insert a template part inside the Post Content block in the Site Editor, when my homepage is configured to display a static page: On a similar note, I am also able to insert a Post Content block inside another Post Content block. I can also insert the Post Content block in the post editor. I don't think either should be possible. Is that something we should address here or separately? |
This is the existing problem with have with
This should be looked at separately. Also we need to be able to add
I left this as is, as even we enforce the hiding of the block in post editor, with that setting we could hide in template editing mode as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ntsekouras.
This approach works and fixes the blocker issue.
I think we all agree with @gziolo's comment that we need a more general API in the long run.
Indeed, I kind of forgot that allowedBlocks (and disallowed blocks) only work for direct children) meaning the solution here is not well-suited to solve this problem now. For me we should take time to find the right solution for this long term and not rush anything into 5.9 in that case. |
@youknowriad, generally I'm always for finding the right solutions, but we had to take shortcuts for other blocker issue. So, I'm a little confused about deciding when to go with a temp solution or not. |
Sounds good to me, I also want to look at ways we can make registered blocks not so prominent — yet discoverable via search, etc, so we can favor variations instead of source blocks (query vs post list). |
Sounds good. I'll close this PR for now. Thanks for the input all 👍 |
@Mamaduka I think it's hard for me to compare things in general. Could you give move examples of contradictory decisions? Errors are always possible of course, but personally, I try to have a reasoning for each shortcut separately. It's always a hard decision to make. |
I'm happy to expand on my reasoning here. Since the stop gap solution won't stop us from adding template parts to post content anyway aside some special use-cases (root level block-content block or post editor), it won't prevent us from having to deal with this in the future anyway. We'll still potentially have template parts inside post content blocks so why bother with a stop gap solution, especially since that solution means introducing a new API that we know don't work. |
@youknowriad, thanks for taking time and explaining your reasoning 🙇 It was a more general question. I understand there's no rule of thumb for this kind of decision, but one can always learn a thing or two :) |
Would there be a way to caution people about this in the mean time? With 5.9 template parts are going to become more prominent, and I worry folks might start using them interchangeably with reusable blocks if they are able to insert them in to posts. It would be a real pain for folks who are doing that to find that they cannot do so after a future update. |
I guess we could add a message somewhere to the block itself after it's inserted maybe? |
That or something like a Notice would be good. Any small thing we can do to discourage this behaviour and avoid headaches down the road feels like a win. |
Can we try replicating the same logic we use to prevent rendering the same instance of Template Part into itself? Instead we could try to halt rendering in the wrong context? |
Ah yes, the Post Content block does something similar when you insert it in a post. That would be perfect as an interim. |
@ntsekouras If this was closed does that mean that #30668 can be remove from the 5.9 "Must Haves"? |
I'm not sure about removing the issue from the board, but definitely we need a different approach from this PR. |
No, #30668 is still targeted to be fixed for 5.9, we just need a different approach as Nik suggested. In any case, we shouldn't rush anything as pointed out in a comment above. Ideally, we should not show the Template Part block in the Post Editor inserter only to remove it in the following release, as it could confuse users. |
Resolves: #30668
This PR takes an approach of introducing a new
__experimentalDisallowedBlocks
property which is used inPost Content
block, in combination of hiding the Template Part block when we are not in template mode in post editor.We need both because in post editor the post content is not rendered as a single
Post Content
block.By not unregistering the block the existing content can work as before without disruptions.
Testing instructions
Template Part
post/page template
and observe that the block is available only outside thePost Content
blockNotes
I'll update the tests if the approach is deemed okay.