-
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
Suggestion: Block templates in page template header #3835
Comments
Interesting idea. See also: #3588 |
This is a powerful concept and one which is seen in several existing field libraries such as ACF and CMB2. I'd love to see it in Gutenberg. |
The plan for pages was to introduce a function like In the meantime, a solution like one of the above might make sense as just populating the content area. If anyone wants to look at a proof implementation, that'd be great. |
The problem I see with this is trying to implement a PHP array in a comment. That will be tedious and prone to error. Perhaps we could have a function where we register block templates with an internal name, much like how we register post types? Then we could just reference the internal name for the block template and WordPress will have already loaded it. This would also make it easier if someone needed to use (or change) the same block template across different page templates (or post types). |
In case someone needs a feature like this I iterated on the work of @jasonbahl in #3588 and made a PoC plugin for my own use case https://github.com/generoi/wp-gutenberg-templates. I wont be maintaining it and will look to deprecate it for my own use cases once Gutenberg has a better alternative. At the moment you register a template using: add_action('init', function () {
register_gutenberg_template('foobar', [
'post_type' => 'page',
'name' => __('Foobar'),
'template' => [
['core/image', ['align' => 'left'],
['core/paragraph', ['placeholder' => __('Foobar')],
],
'template_lock' => 'all',
]);
}); It will then show up as a page template option even if no template file exists (regular template fallback applies) and read the template definition when the Page template attribute changes in the Gutenberg editor. I added some basic validation that prompts for confirmation before replacing existing content but at the moment everything is very untested. Just thought I'd mention it if someone wants a starting point |
I could see this slipping to |
This is definitely a phase2 thing and I don't want it to be rushed. |
Closing this. This is the whole idea of FSE. I encourage everyone to follow the label for updates https://github.com/WordPress/gutenberg/issues?q=is%3Aissue+is%3Aopen+label%3A%22%5BFeature%5D+Full+Site+Editing%22 |
Although blocks may in many cases replace traditional page templates, there are still a number of cases where different templates are needed
Automatically adding blocks on registering a CPT works well, this could be extended to page templates.
Possible Solution
As page templates are automatically included by WordPress rather than through an action (as with CPTs), this could potentially be controlled by the header comments that already dictate the template name.
Alternatively, it may be preferable to keep the initial blocks as an action instead, with a new function like the below:
Todos
The text was updated successfully, but these errors were encountered: