WordPress Development Asked by Paranoid Android on January 1, 2021
I want to create a custom Gutenberg block with these features below
I can’t find the documentation for repeated components or any good code examples. I feel like this a very important part of block development as this kind of blocks are very common in most projects.
So, any code example/documentation or guidance is very much appreciated.
Example: Image Slider with a caption, Multiple ‘card’ like blocks inside a parent block.
I think the best way to approach this is by creating 2 blocks with a parent -> child relationship.
The child block would be a nested block only available within its parent block. Note the parent defined below.
registerBlockType( 'prefix/childblock', {
title: __( 'Inner Child Block' ),
parent: ['prefix/parentblock'],
attributes:{ ...//the rest of your block code continues
Then in the parent block you have innerblocks - where the child block can be added multiple times.
edit: props => {
const { className } = props;
return [
<div className={className}>
<InnerBlocks
allowedBlocks={['prefix/childblock']}
/>
</div>
];
},
Answered by Lyle Bennett on January 1, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP