We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Display metaobject in liquid

Display metaobject in liquid

mybzzfarm
Visitor
3 0 0

I have a metaobject called beekeeper, which has 4 fields - name, location, profile_image, total_hives. This metaobject is linked to a product via metafield called hive.beekeeper

 

The issue is that I cannot display meta values. The closes I got was with {{ card_product.metafields.hive.beekeeper }}, where I at least got gid://shopify/Metaobject/72501821775 in response.

 

I need to display name value. Dawn Theme. Please help 

Replies 8 (8)

Guleria
Shopify Partner
4299 825 1189

Hello @mybzzfarm ,

 

Can you please share few screen-shots how and where you created metaobjects?
or a short video ?

 

Thanks

- Elevate Your Store with Expert Shopify Services. Email: guleriathakur43@gmail.com - Need a quick fix or a tailored customization? I’ve got you covered.
- Looking to enhance your pages? Try GEMPAGES- a powerful drag & drop page builder.
- Let’s make your store stand out. Get in touch today!
- My Apps: Productify Groups – Smart product grouping made easy.
mybzzfarm
Visitor
3 0 0

Hi,

 

I do apologise I couldn`t reply earlier. Please see screenshots below.

 

metaobject 3123123.pngmetaobject product 313424.png

 

 

Also, I did make a little bit of progress by using this bit:

 

   {% for beekeeper in shop.metaobjects.beekeeper.values %}
        <div class="profile-image-holder">
        <img src="{{ beekeeper.profile_image.value }}" alt="{{ beekeeper.name.value }}" class="beekeeper-profile-image" width="30px" height="30px">
        </div>
          <div class="beekeeper-info">
            <p>{{ beekeeper.name.value }}</p>
            <p>{{ beekeeper.location.value }}</p>
            <p>Total Hives: {{ beekeeper.total_hives.value }}</p>
          </div>
      {% endfor %}

 

But of course it iterates and displays all entries, whereas I simply cannot figure out how to better write IF statement to display only entry assigned to the current product (it`s to be displayed on a product card within collection, not on a product page).

 

Hope you can help me.

enwartahir
Shopify Partner
3 0 3

Hello. Please try this for all the information show on product collection page. 

{% if card_product.metafields.custom.hive.beekeeper %}
  {% assign beekeeper = shop.metaobjects.beekeeper[card_product.metafields.custom.hive.beekeeper] %}
  
  {% if beekeeper %}
  <div class="profile-image-holder">
    {% if beekeeper.profile_image != blank %}
    <img src="{{ beekeeper.profile_image | metafield_tag }}" alt="{{ beekeeper.name }}" class="beekeeper-profile-image" width="30px" height="30px">
    {% endif %}
    </div>
    <div class="beekeeper-info">
      {% if beekeeper.name != blank %}
      <p>{{ beekeeper.name }}</p>
      {% endif %}
      {% if beekeeper.location != blank %}
      <p>{{ beekeeper.location }}</p>
      {% endif %}
      {% if beekeeper.total_hives != blank %}
      <p>Total Hives: {{ beekeeper.total_hives }}</p>
      {% endif %}
    
      <!-- Add other beekeeper fields as needed -->
    </div>
  {% else %}
    <!-- Optional: Display a message if the beekeeper is not found -->
    <p>Beekeeper information not available.</p>
  {% endif %}
{% endif %}

You may use only product instead of card_product for product page.  

mybzzfarm
Visitor
3 0 0

This is what I`m trying to achieve: every hive is assigned with beekeeper, and I want to display a small icon of a beekeepers profile picture. At the moment, since the loop iterates through all entries, you can only see the latest one, but I need something to define "if this product is assigned with this entry from metafield, then display this info"

 

shopify metaobjects.png

enwartahir
Shopify Partner
3 0 3

Try this for collection cards:

{% if card_product.metafields.custom.hive.beekeeper %}
  {% assign beekeeper = shop.metaobjects.beekeeper[card_product.metafields.custom.hive.beekeeper] %}
  
  {% if beekeeper %}
  <div class="profile-image-holder">
    {% if beekeeper.profile_image != blank %}
    <img src="{{ beekeeper.profile_image | metafield_tag }}" alt="{{ beekeeper.name }}" class="beekeeper-profile-image" width="30px" height="30px">
    {% endif %}
    </div>
  {% endif %}
{% endif %}
julson11
Explorer
50 1 7

Hey guys,

 

I try to display new shopify metaobjects with liquid code.

julson11_0-1733061058270.png

I would like to show the content of the field "Informationen zu Allergenen". Which could be "Sulfite", "Nuts", "Egg" and so on..



What variable do I need to use to show it in custom liquid inside the customizer?

Brycesmit
Visitor
2 0 0

I'm running into the same issue. I tried a lot to show the allergens. But, no luck so far. Anyone has a solution?

Wine
Shopify Partner
3 0 0

As you can see in the screenshot, the field has the namespace “shopify.allergen-information”.

You can therefore access this field under the following objects:

  • product.metafields.shopify['allergen-information']
  • item.product.metafields.shopify['allergen-information']
  • card_product.metafields.shopify['allergen-information']

 

 

{% for field in product.metafields.shopify['allergen-information'].value %}
  {{ field.label }}
{% endfor %}

 

 

The contents in metafields are accessible under the value namespace. Since it is a list, you iterate with a for loop.