-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
How post_meta is handled on multiple instances of the same block? #5599
Comments
Question: Why were you inclined to use meta for font size, and not the default comment attributes, which are just as well supported on the server for varying inline style? To me, one of the advantages of meta as an attribute source is that it applies globally to all instances of the block. |
Discussed in #core-editor weekly triage: https://wordpress.slack.com/archives/C02QB2JS7/p1522944073000951 |
We need to create block meta that could be registered with a function named for example: register_block_meta |
@DOUARA Could you please create a separate issue which explains your use-case and the proposed benefit of what you're requesting? |
@aduth With attributes stored only in the comment delimiter, css could be added inline only, and when we have style rules with media queries and pseudo selectors we will be forced to add css with style tag on the body which is a bad practice. |
Issue Overview
Right now, when you set an attribute as
source: 'meta'
, Gutenberg stores the meta on the database properly:And then we declare the existence of this meta like this, so the REST API will know how to handle the meta:
But, when you add multiple instances of the same block, all of the instances will pull data from the same post meta. This means that, if you change the attribute on one block, it will change on all blocks. It makes sense when your post meta is something that should be set globally for the post. But what if I want to store some post meta specifically for your block?
A real example: I'm creating a block that has some styles attributes. If I have two of these blocks,
fontSize
, for example, should be a post meta that returns an array with two values, each one for each block. I'm doing this because I'm trying to usewp_add_inline_style
to generate styles for each instance of my block and add it to thehead
of the page.Steps to Reproduce (for bugs)
Expected Behavior
While the current behavior makes sense, we should also allow to store post meta per block, and not only per post. There might be a better approach for this, rather than using post meta, but it makes sense to have something like this if we want more flexibility with block attributes. I tried using the
render_callback
for theregister_block_type
php method, and generate the whole markup with PHP. You can usewp_add_inline_style
there, but it won't be printed on thehead
of the page. It will be printed in thebody
, which works but it is not valid html.Screenshots / Video
https://drive.google.com/file/d/1yeMU1yRWrvsTYSYCBKjhE7cWh3m2PmIa/view?usp=sharing
The text was updated successfully, but these errors were encountered: