• Micha?l

    (@michaelperrin)


    Hi everyone!

    This is my first message here, so I hope I am at the right place to ask my question!

    To give the big picture of what I need to do, I will simplify my problem.
    I have created two custom Gutenberg blocks, let’s call them slider and slide. I would like to insert slide in the code returned by the edit function of slider, and not using InnerBlocks with a template.

    I can’t use InnerBlocks as it adds several <div> elements around the child element that breaks the styling.

    Sample of the slide block:

    registerBlockType('slide-block', {
    	// ...
    	parent: ['slider-block'],
    
    	edit: () => (
    		<div className="slide">
    			Slide content
    		</div>
    	);
    	// ...
    });

    Sample of the edit function of the slider block:

    edit: () => (
    	<div className="slider">
    		// INSERT SLIDE BLOCK HERE
    	</div>
    );

    The slide class has to be a direct child of the slider class for styling reasons, and that is why I can’t use InnerBlocks.

    Any help or idea would be greatly appreciated ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I don’t see any way to achieve what you want. You could instead of using inner blocks, collect content data through other means, similar to what the gallery block does. Either that or alter the styling so that the extra divs do not factor into the layout.

    I suppose you could use JS to clean out the extra divs after the page loads. Hardly an optimal solution.

    Thread Starter Micha?l

    (@michaelperrin)

    Thank you very much @bcworkz for your answer. This confirms what I thought, as I tried a lot before asking here ??

    Making my “WYSIWIG” carousel block will be harder then. I will check the gallery block that you mentioned and keep everyone poster if I find a good solution to my problem.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Insert a custom block into a custom block (without InnerBlocks)’ is closed to new replies.