Support

Account

Home Forums Gutenberg with data from parent block

Unread

with data from parent block

    • Koshimon

    • September 16, 2020 at 6:59 pm

    (edit: sorry for the title, seems like <InnerBlocks> is not allowed in the title…)

    Hi everyone ๐Ÿ™‚

    I’m trying to use <Innerblocks> and have some context to the parent block. For example I want to define an ID in the parent block and all the <InnerBlocks> should use this ID for something. Or maybe on the parent the user can chose the color and all <InnerBlocks> then have the same color (this is only an example, I know CSS^^).

    I found some ideas how to achieve this but for now I wasn’t able to really get it working.
    Based on the site https://developer.wordpress.org/block-editor/developers/block-api/block-context/ block context should be the solution to this.

    Just create a parent block with attributes and add the context:

    
        "attributes": {
            "recordId": {
                "type": "number"
            }
        },
        "providesContext": {
            "my-plugin/recordId": "recordId"
        }
    

    That’s what I tried, of course with PHP:

    
    'title'             => __($name),
    'attributes'        => [
    	'recordId'  => [
    		'type'  => 'number',
    	]
    ],
    'providesContext'   =>  [
    	'my-plugin/recordId' => 'recordId'
    ]
    

    As soon as I add these lines, everything stops working in the backend. So basically the next steps to get the context in the <InnerBlock> is not possible because I can’t configure the parent block.

    Does anyone have an idea how to achieve this?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.