-
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
Simplify template part block attributes #26950
Comments
Upon further thought, I don't think it would be such a good idea after all to remove the I still think the |
Totally missed this issue! |
I don't think |
Are you sure? Can you give an example? |
The sync that automatically converts theme-provided files into templates and template parts auto-drafts, only check if there are already either Reasoning is that only templates and parts with status With this in mind, we can end up with slug/theme duplicate See for example what I have on my dev site right now: (As an aside: I thought |
One example could be just creating 2 new template parts in the editor. Either through adding the block and creating a new one through the placeholder, or selecting blocks and using the ellipsis menu to create a template part out of them. These template parts will be made with the same slug and be named 'Untitled Template Part', they will also have the same theme term. So currently Also with the most recent changes, new template parts that are created will have the active theme's name set as their theme term. So we could find similar examples where a user might name a template part "header", where the theme had created a "header" template part. The template part block is set up to try to find an entity by slug/theme combo alone if there is no I do have some other concerns with the current set up though. The combination of these things does create the potential for some sticky situations if I am understanding the recent changes correctly. Continuing with that last example we now have a theme supplied "header" and a custom (from scratch) created "header" both with the same slug/theme combo. Now the unedited theme template referencing the header only by slug/theme will resolve to reference the custom template part since it prioritizes When custom template parts were created with a separate value for the theme term, this was not an issue. The only conflict would be between an unedited theme supplied template part and a customized version of that same theme supplied template part, in which case resolving to the customized one made sense. But now we have an issue where a created from-scratch custom template parts could override unedited theme supplied ones when referenced from those base template part blocks that don't have a |
Wouldn't it be better to name it Untitled 2, or require the user to give it a unique name before it's saved, etc?
Again, why not name it header-2, or show an error message that the name is already taken? |
This may be a bigger issue than I even realised, because there is a core function I literally just discovered this now with a template part showing up as "Template Part Not Found" because it was referencing an auto-draft by ID that got automatically deleted. Then I removed the ID attribute, left the slug and theme attributes intact and it started working again. Come to think of it, there are also plugins like Advanced Database Cleaner and others that can flush auto-drafts on-demand, so it's really not a good idea to assume that a template part will always have the same ID. |
Ah! So, on one hand we definitely need a way to prevent multiple templates with same slug and theme term — and this regardless of anything else, as it makes it unpredictable which one will be eventually resolved. I'm also indeed convinced that while the ID as unique identifier is useful in most cases, templates (and template parts) resolution is not one of them: we only need to rely on slug and theme term. |
That's how it was originally implemented. It proved to be a bit clunky UX wise, and wasn't necessary technically. After working through some design iterations it was updated to not require unique slugs and no longer append |
@Copons I'm just curious about this comment you made at #27277:
Does that mean I was on to something by proposing to remove the The reason I reneged is I was thinking of cases where a template part is included in a post or page. These blocks would persist after a theme switch (unlike those inside templates) and would risk unexpected output if they don't specify a theme. On the other hand, template parts don't really belong in posts and pages, and you'd probably expect them to be hidden from the block inserter, so if a user managed to sneak one in, then perhaps it should be at their own risk? |
Reverting this issue back to it's original title. I understand the postId attribute is now gone with #27910, and there is discussion on removing the theme attribute as well. |
After working on #31971, I'm further convinced by the above argument, so I will go ahead and close this issue. |
Is your feature request related to a problem? Please describe.
Currently, the template part block supports four attributes:
postId
,slug
,tagName
andtheme
. In light of #26650 being merged, there is now no longer a need for thepostId
andtheme
attributes.The purpose of the
theme
attribute was to preserve the rendering of user-edited templates that survived a theme switch. Now that all templates are retired from use upon theme switch, there is no longer a need for this attribute.As for the
postId
attribute, I think its purpose was to locate template parts that the user created independently of the theme. This idea of theme-less templates/parts is no longer being supported for the time being.Describe the solution you'd like
Simplify the supported attributes of the template part block to just
slug
andtagName
, as these are now the only ones needed.The block would then render the template part from the current theme with the specified slug, if it exists. It shouldn't need to look through an inactive theme.
Also related: #25845, #22717
The text was updated successfully, but these errors were encountered: