-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lib: Add template part CPTs and their theme resolution logic. #18339
Conversation
Does it need to be different than the regular block templates? |
It simplifies a lot of the resolution code. |
Can you elaborate more. It feels to me like it's just a "virtual" distinction, today in themes you can have |
Querying the file system to look for templates vs. template parts becomes easier if they are in separate directories. Furthermore, writing From Dotcom's exploration:
|
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.
This looks solid to me, good to go. I agree that separating the folder for template parts from the one for templates makes sense. It's a very common pattern today which helps a lot with distinguishing the two, especially because they can easily pile up.
Follows #17512
Description
This PR continues the template API work by introducing the concept of template parts.
Template parts are blocks with the following attributes:
slug
: The name of the template, e.g.'header'
.theme
: The name of the theme that provided the part, if any, e.g.'twentytwenty'
ornull
for no theme.id
: After a template part has been modified, it will be saved as awp_template_part
post. This attribute references that post, if any, e.g.8
.Themes provide template parts in a
/block-template-parts
directory as html files where the name of the file matches their'slug'
attribute.For example:
/block-templates/single.html
:/block-template-parts/header.html
:When loading in the editor, all template parts without an
id
will get an auto draft with the relevant file's contents in them so that the editor can load the contents and potentially persist any changes. Once the block is implemented, this will have to also call the block's server rendering callback to check for any nested template parts.When loading in the front end, the block's server rendering callback should output either the relevant file's content if there is no
id
, or the relevant post content if there is one.We need a
theme
attribute to differentiate between template parts with the same slug originating from different themes. When you save changes to a given template, it and all its nested template parts will persist across theme switches. Even though by that point those template parts will haveid
s and will be renderable regardless of what the new active theme provides, we need a way for the user to insert new instances of them and that is wheretheme
comes in handy. For now, we store the value in post meta so we can do meta queries.How has this been tested?
This was mainly a foundational change, but it was verified that the Full Site Editing experiment still works as expected and that nothing changes when it is not enabled.
Checklist: