Help! Metaobject list of files show up as "no image" using Custom Liquid

Solved

Help! Metaobject list of files show up as "no image" using Custom Liquid

Rueben
Shopify Partner
5 0 0

Hi all,

I'm trying to print a list of files (images) through custom liquid code and for some reason, Shopify recognizes what I'm trying to do but only displays the placeholder "no image" instead of the images I added to the metaobject. As seen below:

Scherm­afbeelding 2024-06-24 om 10.01.54.png

 

The reason I'm doing it this way is because I want to be able to select a list of pictures I already uploaded for specific Influencers we partner with and doing it this way makes it easier for my co-workers to select pictures for each influencer, instead of having 9 different metafields inside the metaobject for each picture. I've shown my metaobject structure below:

Scherm­afbeelding 2024-06-24 om 10.02.54.png

Scherm­afbeelding 2024-06-24 om 10.03.15.png

I don't understand why it is not working as I can access the metaobject information fine (the following code prints the name fine:

{% assign influencers = shop.metaobjects.influencer.values %}

{% for influencer in influencers %}
<h2>{{ influencer.name }}</h2>
{% endfor %}
)
The code I'm using for the printing of the images is:

{% assign influencers = shop.metaobjects.influencer.values %}

{% for influencer in influencers %}
<h2>{{ influencer.name }}</h2>

{% assign gallery = influencer.gallery | split: ',' %}
{% for image in gallery %}
{% assign image_url = image | img_url: '500x' %}
<img src="{{ image_url }}" alt="{{ influencer.name }}">
{% endfor %}
{% endfor %}

If anyone has any idea what I'm doing wrong or how I can approach this differently, please help. I have been stuck on this for quite some while and feel like this should be doable. If not, also please tell me.

 

Thanks for ANY help in advance!

Accepted Solution (1)
wo
Shopify Partner
188 42 42

This is an accepted solution.

{% assign influencers = shop.metaobjects.influencer.values %}
{% for influencer in influencers %}
<h2>{{ influencer.name }}</h2>

{% assign gallery = influencer.gallery.value %}
{% for image in gallery %}
{% assign image_url = image | img_url: '500x' %}
<img src="{{ image_url }}" alt="{{ influencer.name }}">
{% endfor %}
{% endfor %}

View solution in original post

Replies 4 (4)

wo
Shopify Partner
188 42 42

Why add this?

wo_0-1719218237413.png

 

Rueben
Shopify Partner
5 0 0

It is supposed to split the influencer.gallery values from a string to an array. If I remove that part, the code doesn't work anymore.

wo
Shopify Partner
188 42 42

This is an accepted solution.

{% assign influencers = shop.metaobjects.influencer.values %}
{% for influencer in influencers %}
<h2>{{ influencer.name }}</h2>

{% assign gallery = influencer.gallery.value %}
{% for image in gallery %}
{% assign image_url = image | img_url: '500x' %}
<img src="{{ image_url }}" alt="{{ influencer.name }}">
{% endfor %}
{% endfor %}
Rueben
Shopify Partner
5 0 0

Thanks! This seem to work! Can you explain to me what I did wrong?