Access alt-Text of images placed in meta object

RedwoodTH
Visitor
3 0 0

In the following code the alt-text of the image does not appear: the meta-object does not have value in the "referenz.image.alt". Is there any way to get the alt-text in a similar way? And YES: the images saved in the meta-object have an alt-text!

 

{% assign referenzen = shop.metaobjects.referenzen.values %}
{% for referenz in referenzen %}
  <div class="image-item">
    {{ referenz.image
      | image_url: width: 1420
      | image_tag:
        loading: 'lazy',
        class: 'masonry-card__image'
    }}
  </div>
  <div class="image-caption">{{ referenz.image.alt | escape }}</div>
{% endfor %}

 

Replies 2 (2)

KabirDev
Shopify Partner
244 60 67

In your code, if `referenz.image.alt` is not returning the alt text, it might be due to how the image object is structured within the `metaobjects`. To access the alt text, ensure that the `image` object in `referenzen` actually contains the `alt` attribute. Alternatively, consider using a different method to fetch the alt text, possibly by accessing the image details through Shopify's API or checking if there's a different attribute in the `metaobjects` structure that holds the alt text.

If my answer helps, please give it a Like and Accept as Solution.
- Control payment methods visibility at checkout by KlinKode PayRules app.
- Contact me directly at shahriar@kabirdev.com
- You can join in our Facebook group for Shopify help.
RedwoodTH
Visitor
3 0 0

Yes, at this point I'm sure the `image` object in `referenzen` does not contain the `alt` attribute. Also, I could not find any information on the structure of metaobjects suggesting that the alt-text of images can be accessed via a specific attribute... 'referenz.image.alt' was my best guess. Is there any other way to get the alt-text via the image URL from 'referenz.image'?