-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Conditionally loading block templates classic themes #45341
Comments
@WordPress/block-themers tagging in this crew as I think this will be of interest! |
👋 So I understand, the suggestion is to enable classic themes to specify a different file path for a block-based template to override in the hierarchy? Apologies if I'm missing something, but why not just enable the theme support and supply the block based version of the template in the location that Core will look for, e.g. |
That would make sense as well. Just allowing a configurable array of which templates are being loaded would be good enough, I think. |
Why is a configurable array necessary? Currently if a block template is provided and the theme support is added + enabled, the block template will override the classic one accordingly in the hierarchy. For example: WordPress/wordpress-develop#3545 — archive pages are rendered with the block template and all other pages with the classic template. |
It just occurred to me that filtering out the templates you don't want to load using the That would solve the issue. I'm not sure why I didn't think about this before. 😶🌫️ Thank you for being so helpful! |
Happy to help and try to understand different use cases! |
@abaicus is it okay if we close this out considering? Perhaps it's worth updating this handbook page around this specific use case since it seems to have resonated too: https://developer.wordpress.org/themes/block-themes/converting-a-classic-theme-to-a-block-theme/ |
@annezazu Yes, I think we can close the issue. It would be great if it could be mentioned in the handbook. 👍🏻 Thank you for all the help! |
I think we may need a little bit more information to help us update the documentation. @abaicus Would you be able to share an example where you are using the filter? |
@carolinan I've added this functionality in this commit: Codeinwp/raft@a3d9919. Please let me know if you think any additional details are needed! 👍🏻 Thank you! |
What problem does this address?
It is currently impossible to specify which templates should be loaded inside classic themes.
There are two theme supports to enable block templates and template parts:
A classic theme might implement a complex archive layout with many customization features but still want to allow the possibility to use a template for the archive based on a customizer setting.
I believe that this extends to block-based themes as well. If you want to define templates for CPTs (e.g., WooCommerce Single Product), these will be loaded automatically, regardless of the plugin’s state. When it comes to classic themes, authors would probably want to allow the user to pick which templates he intends to override with block templates.
I’ve seen that WooCommerce has managed to load templates from the plugin in a custom class, but that feels a bit cumbersome.
What is your proposed solution?
Allowing an arguments array with which templates to be loaded for both theme supports could be a good solution:
The text was updated successfully, but these errors were encountered: