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 6 (6)

Guleria
Shopify Partner
3944 791 1120

Hello @mybzzfarm ,

 

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

 

Thanks

- Drop an email   if you are looking for quick fix or any customization
- Email: guleriathakur43@gmail.com Skype: live:navrocks1
- Try GEMPAGES a great page builder
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
49 1 6

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?