Support » Plugin: Gutenberg » Dynamic InnerBlocks templates

  • Resolved Danny de Haan



    I’m currently building a new products section for our website. We want to use Gutenberg so our editors can create archive pages easier instead of working with ACF’s flexible layouts.

    They have the choice to create a product overview block. With the following options:
    Rows: 1 or 2
    Columns: 1, 2, 3 or 4
    Products: Random, Sort by date, Popularity and handpicked.

    I have 2 blocks:
    ProductOverview and ProductBlock. The ProductOverview is loading the ProductBlock component for Random, Sort by date or popularity or the InnerBlocks component when handpicked is chosen.

    Random, Sort by date and Popularity are working. But when i choose handpicked now, the number of ProductBlock’s doesn’t change. My InnerBlock looks like follows:

    	template={this.getProductOverviewTemplates(this.props.attributes.rows * this.props.attributes.columns)}
    	allowedBlocks={ [ 'fw-gutenberg/product-block' ] }
    	templateLock={ true }

    As you can see, the InnerBlocks has an attribute named template. The method “getProductOverviewTemplates” receives the number of templates it should return.

    getProductOverviewTemplates(count) {
    	let templates = [];
    	for (let i = 0; i < count; i++) {
    	return templates;

    When i select 1 row and 2 columns, getProductOverviewTemplates is returning the following:

    With 2 rows and 2 columns, i’m getting:

    But the number of ProductBlocks in my InnerBlocks container is still 2.

    I’ve already tried to do a forceUpdate(), but that doesn’t work either.

    Someone who can help?

Viewing 1 replies (of 1 total)
  • I’ve seen this before while trying to get my own multi-column block working. It was related to my “name” for the InnerBlock’s layouts property’s objects (ie: el(InnerBlocks, {layouts: [{name: ‘some-name’, …}, {name: ‘some-other-name’, …}])

    The names have to be consistent (ie, first column name should always be column-1, or columnA, or whatever, and the second column should always be column-2, or columnB, or whatever). In my case, I had been changing the names of the columns based upon other user-configured characteristics.

    However, I don’t see you using layouts, so this anecdote may not help you.

Viewing 1 replies (of 1 total)
  • The topic ‘Dynamic InnerBlocks templates’ is closed to new replies.