Support

Account

Home Forums Gutenberg Limit amount of Innerblocks to x number Reply To: Limit amount of Innerblocks to x number

  • @heerko @duck life
    First, you need to create a counter variable that keeps track of the number of blocks that have been added. You can do this by creating a variable count that is initialized to 0.

    Next, you will need to create a function that increments the count variable each time a new block is added. You can do this by creating a function addBlock that increments the count variable by 1 each time it is called.

    Then, you will need to bind the addBlock function to the appender so that it is called each time a new block is added.

    Finally, you can use an if statement to check the value of count and hide the appender if count is equal to 2.

    Here is some example code that demonstrates how you could implement this:

    let count = 0;
    
    function addBlock() {
      count += 1;
      if (count === 2) {
        // hide the appender here
      }
    }
    
    // bind the addBlock function to the appender
    document.getElementById("appender").addEventListener("click", addBlock);