• I just want to retrieve the information of an innerblock contained in X innerblocks.

    Can someone explain to me the bug here??
    What would be the “right way” to perform this operation?

    function getSubChildBlockByLevel(childBlock, loop){
    	loop++;		
    	if(loop < attributes.lvlchild){
    		getSubChildBlockByLevel(childBlock[0]?.innerBlocks, loop);
    	} else {
    		console.log("In_Function--------");
    		console.log(childBlock);
    		return childBlock;
    	}
    }
    
    var loop = 0;
    var childBlock = select('core/block-editor').getBlocksByClientId(clientId)[0].innerBlocks
    console.log("First ChildBlock--------");
    console.log(childBlock);
    
    var subChildBlock = getSubChildBlockByLevel(childBlock, loop);
    console.log("After_Return--------");
    console.log(subChildBlock);

    Console return :

    // With : "attributes.lvlchild" = 2
    
    First ChildBlock--------
        0: 
            attributes: {...} 
            clientId: "8ae88548-b53b-4bc6-9eb8-8c57ba68c9fd"
            innerBlocks: Array(1)
                0: 
                    attributes: {...} 
                    clientId: "f72a3307-0488-4bf6-827c-00e8e2b2f43b"
                    innerBlocks: (4)
                (...)
    
    
    In_Function--------
        0: 
            attributes: { } 
            clientId: "f72a3307-0488-4bf6-827c-00e8e2b2f43b"
            innerBlocks: (4)
        (...)
    
    
    After_Return--------
    undefined

    • This topic was modified 1 year, 4 months ago by white8ook.
Viewing 1 replies (of 1 total)
  • Moderator Kathryn Presner

    (@zoonini)

    Hi @white8ook – I’ve asked a couple of developers to have a look at this, and they said it would be really helpful if you could put your project into a GitHub repo so they can see your code in context. Let me know if you’re able to do that, thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘gutenberg blocks loop through multiple innerBlocks’ is closed to new replies.