-
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
Add support for custom templates in FSE themes #27778
Conversation
Size Change: -317 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
This sounds great. It might require some alignment with how the default template types are structured: gutenberg/lib/full-site-editing/default-template-types.php Lines 16 to 19 in 5425353
As of today it's:
It looks like i18n support would need to be handled as well. |
Wonderful. The exiting feature is called "Page Templates", referring to the fact that you can only use these when editing pages. It seems to make sense to rename from that since you could create a fresh new "Single" or "Archive" template with one of the custom ones as a starting point. But at the same time, "Custom Templates" may not be the best word, as they are still technically bundled with the theme with all the other templates stored in the I know the term is only used in the code, but is there a better term for it? "Additional templates"? "Unattached templates"? "Optional"? |
I don't hold strong a opinion on the naming. The only places where this is used right now is |
I like "Templates". |
Custom templates are by default assigned only to pages, but you can specify they should be made available to other post types: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-page-templates-for-specific-post-types I'm not sure we should use just "Templates" since all the other files (or posts in |
"Supplementary Templates" is accurate, but is a bit long and doesn't roll off the tongue. "Extra Templates" may be best then? |
I'm confused, why not just page templates or custom templates? |
I wouldn't object to either of those. But here's my reasoning.
|
Not for anything, for different post types if so specified. I think it's important to have some continuity and not add to the burden of concepts. |
Page Templates would probably be for for the SEO then. |
Ok so I updated to use "postTemplates" as a config key and used the format suggested by @gziolo |
cb46ad0
to
a19fca1
Compare
* @param WP_Post $post The post being edited, provided for context, or null. | ||
* @return array (Maybe) modified page templates array. | ||
*/ | ||
function gutenberg_load_fse_page_templates( $templates, $theme, $post ) { |
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.
not blocking, but we should start dropping the "fse" term in functions, etc, to something more general like load_block_page_templates
add_filter( 'theme_post_templates', 'gutenberg_load_block_page_templates', 10, 3 ); | ||
add_filter( 'theme_page_templates', 'gutenberg_load_block_page_templates', 10, 3 ); |
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.
@youknowriad What about other post types? IMO the generic theme_templates
filter should be used here.
Why was WordPress uses the term "post template" internally (see |
I think "post" can become quite confusing (particularly for a more user facing API, which building a theme is) because we already have templates that apply to the content of a post (on a CPT). Page signals more clearly it is applying beyond the content (the page template for a post type makes sense). Also the fact these templates are by default only available for post type = page. The fact that internally everything is a post doesn't necessarily mean, in my opinion, we should call something like menus postMenus on more surface level APIs. In any case, perhaps |
This brings the "custom templates" feature from classic themes to FSE themes. While in classic themes, this is done by adding a comment at the top of the template file, this can't be done for FSE themes since they are just HTML files.
(it might change later but let's do with what we have now)
So in order to support these, developers need to:
about.html
/custom.html
... to theblock-templates
folder.customTemplates
property to the root level oftheme.json
like soand that's it. The templates will show up in the template picker on the sidebar of the editor.
In terms of UI and integration with the template mode, we can do a lot more than the old select box. We can show a preview for templates and offer a modal or something like that for folks to pick from... We'd need some design thinking and explorations there. This PR just sets the technical requirements to make it work.