Skip to content
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

Allow block attributes/functionality in a template to be locked/removed #18913

Open
pbearne opened this issue Dec 4, 2019 · 1 comment
Open
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Enhancement A suggestion for improvement.

Comments

@pbearne
Copy link
Contributor

pbearne commented Dec 4, 2019

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

@talldan
Copy link
Contributor

talldan commented Jan 24, 2020

@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 (#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 - #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.

@talldan talldan changed the title pass default text and setting as part of a template Allow block attributes in a template to be locked/removed Jan 24, 2020
@talldan talldan added [Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Enhancement A suggestion for improvement. labels Jan 24, 2020
@talldan talldan changed the title Allow block attributes in a template to be locked/removed Allow block attributes/functionality in a template to be locked/removed Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants