Open pbearne opened 4 years ago
@pbearne, you can already set values for attributes when creating a template. You can see in the documentation below, the example sets an align
value for the image block and a placeholder value for the heading block:
https://developer.wordpress.org/block-editor/developers/block-api/block-templates/#custom-post-types
Any attribute can be set this way. The hardest part is knowing what the attribute is called for each block. At the moment there's no documentation (https://github.com/WordPress/gutenberg/issues/6190). The easiest way is to browse the codebase and look at the block.json
for each block:
https://github.com/WordPress/gutenberg/tree/master/packages/block-library/src
Within the block.json file there's a list of the attributes that can be changes and the type of the attribute. So for heading you can see level
is a number:
https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/heading/block.json
In terms of locking/removing attributes, that's an interesting suggestion. It ties in a bit with what's suggested on this issue - https://github.com/WordPress/gutenberg/issues/7931, though that's more at the editor level.
I've taken the liberty of updating the issue title, given that part of your suggestion was already possible.
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
When creating a template via PHP CPT (or other methods) I Would like to be able to set default content eg. text/values for attributes And to be able to control options by setting defaults and removing options eg. be able to set the heading level in core/heading be able to remove the ability to set h1 in core/heading
Describe the solution you'd like A clear and concise description of what you want to happen. I would like to part of the template array
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. This might be posable via JS but would need a way to target a CPT template set or we could create a complete set of custom blocks but this requires duplicate code (not DRY) and ongoing maintenance
If I am creating a complex page layout with several headers and paragraphs I would to be-able set h2 for the fist and h3 for rest all from the create CPT PHP function