admin管理员组

文章数量:1127085

How can I use a custom block inside another custom block?

I have created a custom block(Block A) that works fine.

Now I am creating another custom block(Block B) and want to embed the Block A inside it.

I tried to use the InnerBlocks like this

<InnerBlocks
    defaultBlock={[
         "Block A"
    ]}
    directInsert
/>

but it doesn't work.

How can I use a custom block inside another custom block?

I have created a custom block(Block A) that works fine.

Now I am creating another custom block(Block B) and want to embed the Block A inside it.

I tried to use the InnerBlocks like this

<InnerBlocks
    defaultBlock={[
         "Block A"
    ]}
    directInsert
/>

but it doesn't work.

Share Improve this question asked Jan 12, 2024 at 13:57 Muhammad KamalMuhammad Kamal 1114 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Finally,I have found a solution. I can pass my custom block to the InnerBlocks inside a template prop.

    const TEMPLATE = [
        [
            "core/columns",
            {},
            [
                [
                    "core/column",
                    {},
                    [["custom/Block A", { url: "this is a url" }]],
                ],
                [
                    "core/column",
                    {},
                    [["core/paragraph", { placeholder: "Enter side content..." }]],
                ],
            ],
        ],
    ];


    <InnerBlocks template={TEMPLATE} />

本文标签: Use a custom block inside another custom block