Dynamic Number of Blocks based on Metafield data

Topic summary

Topic: Dynamically render a variable number of content blocks (image, heading, text) on collection pages using Shopify metafields (custom data fields) in Online Store 2.0.

Problem: The number of blocks varies by collection. Current approach requires many unique metafields per block (image_1, heading_1, text_1, etc.), shown in sets of three (third larger). Manually checking up to 30+ fields or hard-coding counts is not scalable. Array counting failed because any three populated fields were counted; counting by heading works but needs manual updates.

Proposed solution: Add a section setting (e.g., field_set) to specify the number of block sets, then loop from 1..field_set in Liquid. Dynamically build metafield keys (heading_i, text_i, image_i), fetch values, and conditionally render only when present. Sample Liquid code and screenshots were provided to illustrate configuration and output.

Status: Original poster acknowledged the solution and plans to test it; no confirmation of implementation yet. Discussion remains open pending results.

Notes: Screenshots are important to understand the admin settings and expected rendering.

Summarized with AI on February 15. AI used: gpt-5.

Hi there,

So sorry for the slow reply, this looks like a great solution, I haven’t had chance to try it out yet!
Thankyou very much for the detailed response though, I will let you know how I get on with it.