Solved

Liquid: how to output only metafield values that aren't empty in a clean list?

Liquid & Code HelpSolved

Liquid: how to output only metafield values that aren't empty in a clean list?

Devraj Pillai·Asked May 26, 2026
I have ~8 product metafields (custom.feature_1 through custom.feature_8) used as bullet-point features. Some products have all 8 filled, some have only 3. Currently I'm rendering them like:
{% if product.metafields.custom.feature_1 != blank %}
  <li>{{ product.metafields.custom.feature_1 }}</li>
{% endif %}
{% if product.metafields.custom.feature_2 != blank %}
  ...
This is ugly and unmaintainable. Is there a way to iterate metafields by prefix, or a cleaner pattern? Open to restructuring how the metafields are stored too if it helps.

3 Replies

ACCEPTED ANSWER
Fix My Store Team·May 26, 2026
The clean answer: **use a single `list.single_line_text_field` metafield** instead of 8 separate ones. 1. In Settings → Custom data → Products, create one definition: `custom.features` of type "List of single-line text". 2. On each product, you'll get an "Add item" UI to enter as many features as you want, in order. 3. Render with:
{% if product.metafields.custom.features.value.size > 0 %}
  <ul class="product-features">
    {% for feature in product.metafields.custom.features.value %}
      <li>{{ feature }}</li>
    {% endfor %}
  </ul>
{% endif %}
That's it. No `blank` checks because Shopify won't store empty list items. No 8-metafield migration headache (do a one-time migration script via the Shopify CLI or admin API to copy old → new, then delete the 8 old metafields). Bonus: if features need an icon or richer structure, use a **metaobject** ("Feature" with fields `label`, `icon`, `description`) and reference a list of them from `custom.features`.
Devraj Pillai·May 26, 2026
Of course. I forgot list-type metafields existed. Migrated ~200 products with a quick Admin API script in 20 minutes. Theme template went from 40 lines to 5. Thank you.
Jonas Berg·May 26, 2026
Adding for anyone arriving via Google: this pattern also works wonders for `list.url`, `list.collection_reference`, and `list.product_reference` — basically any time you have "N of the same kind of thing", a list metafield beats N individual ones.