Liquid code to loop through a Metaobject list metafield inside a Product List metafield loop

Topic summary

Goal: Iterate a Metaobject list (featured_ingredients) for each product inside a loop over a Product List metafield (pair_with), to output each ingredient’s name and icon. Inside the loop/snippet, attempts returned null despite working outside.

Proposed fix: Assign featured_ingredients inside the related-products loop and reference each product’s metafield (product.metafields.custom.featured_ingredients), then iterate and resolve each entry via the metaobject filter.

Final working solution: In the rendered snippet, the correct product variable is product_ref (passed to the snippet), not product. The list also must be dereferenced with .value. Working assignment:

  • {% assign featured_ingredients = product_ref.metafields.custom.featured_ingredients.value %}
  • Iterate featured_ingredients, then {% assign ingredient = ingredient_id | metaobject %} and render ingredient.icon and ingredient.ingredient.

Notes:

  • The outer loop also uses .value: product.metafields.custom.pair_with.value.
  • Using product.metafields… did not work in this snippet’s context because product_ref is the active product reference.

Status: Resolved. OP confirms product_ref plus .value fixed the issue; alternate suggestion did not solve their specific setup.

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

product_ref and .value fixed it for me. for anyone who is similarly frustrated.

{% assign featured_ingredients = product_ref.metafields.custom.featured_ingredients.value %}

{% if featured_ingredients %} {% for ingredient_id in featured_ingredients %} {% assign ingredient = ingredient_id | metaobject %}

{% if ingredient %}

{{ ingredient.ingredient }}
{{ ingredient.ingredient }}
{% endif %} {% endfor %} {% else %}

No ingredients found.

{% endif %}