Build a section that automatically pulls metaobjects

Topic summary

A developer needed to create a product page section that automatically displays ingredient metaobjects linked to each specific product, rather than showing all ingredients from the entire store.

Initial Challenge:

  • The developer had a product metafield (list of metaobjects) called ingredients_section
  • Looping through shop.metaobjects.ingredients.values returned all store ingredients instead of product-specific ones
  • The original code attempted to filter by comparing IDs, which added unnecessary complexity

Solution Provided:
A community member suggested simplifying the approach by directly iterating over product.metafields.custom.ingredients_section.value, which already contains only the linked ingredients for the current product. They shared working code that loops through this value directly without additional filtering.

Outcome:
The issue was resolved. The developer confirmed their code now works correctly after simplifying it and using the direct metafield value approach as recommended.

Summarized with AI on October 27. AI used: claude-sonnet-4-5-20250929.

Hi everyone!

I’m trying to build a section that automatically pulls ingredient metaobjects into the product page.

What I want to achieve:- I have a product metafield (type: list of metaobjects) called ingredients_section.

  • Each product links to several ingredients metaobjects.

  • I created a reusable Ingredient Carousel section.

  • When I add this section on a product page, it should automatically display only the metaobjects linked to the current product (not all ingredients in the store).

  • I want to avoid manually adding ingredient blocks one by one.

What happens now:- If I loop through shop.metaobjects.ingredients.values, I get all ingredients from the entire store.

  • If I try to use product.metafields.custom.ingredients_section.value directly, it either doesn’t work as expected or requires manual block setup.

Here is my current code:

{% assign linked_ingredients = product.metafields.custom.ingredients_section.value %} {% assign linked_ids = linked_ingredients | map: ‘id’ %} {% if linked_ids and linked_ids.size > 0 %}

{% for ingredient in shop.metaobjects.ingredients.values %} {% if linked_ids contains ingredient.id %}
{% if ingredient.image %} {{ ingredient.title }} {% endif %}

{{ ingredient.title }}

{{ ingredient.description }}

{% endif %} {% endfor %}
{% else %}

No ingredients linked to this product.

{% endif %}

My question:

Is this the correct approach?
How can I make this work so that only the ingredients linked to the current product show up in the carousel automatically?
Or do I need to do something else like manually add ingredient blocks?

Thanks in advance for any guidance!

Hi @Fatina

I think you are close to a solution. Not sure why you have issues with product.metafields.custom.ingredients_section.value or what other code is Ingredient Carousel section. But sometimes you can not link a list to sections and its blocks in the theme editor. But the code you add to the section directly should work.

For me, this code works, and you should not complicate that much. You should have all you need in product.metafields.custom.ingredients_section.value and get data from there. I made a similar metaobject (maybe I missed id) and created product metafield and use following in Custom liquid block of Product Information section. And I know it is not the same as your carousel but data should be the same. Note, it is on Dawn theme:

{% assign linked_ingredients = product.metafields.custom.ingredients_section.value %}
{% for ingredient in linked_ingredients %} 
 	{% if ingredient.image %}  {% endif %} 
 	### {{ ingredient.title }} 
 	

{{ ingredient.description }}

{% endfor %}

2 Likes

Hi Laza
Thanks! Your message really helped, my code works now as I wanted after simplifying it and using

product.metafields.custom.ingredients_section.value

directly, like you mentioned. Appreciate your support!

Best,
Fatina

2 Likes