Support

Account

Home Forums Gutenberg with data from parent block

Solving

with data from parent block

  • (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?

  • Hey @koshimon, did you manage to resolve this?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.