Display a list of Images From Metaobject File List

Hi everyone,

I hope someone can help me solve this.

In Shopify I have a Metaobject with a File field named “projects.files”. The field is listed as “List of files” and accepted specific file types is Images.

I have made an entry for this Metaobject, and I want to display it on the Metaobject template. I have tried with the following (and a lot more codes), but I can’t get it to work:

{% assign projectFiles = metafields.projects.files %}

{% if projectFiles.size > 0 %}
  <ul>
    {% for file in projectFiles %}
      <li>
        {% if file | file_is_image %}
          <img src="{{ file | img_url: 'master' }}" alt="{{ file.alt }}" />
        {% else %}
          <a href="{{ file | file_url }}">{{ file.filename }}</a>
        {% endif %}
      </li>
    {% endfor %}
  </ul>
{% else %}
  <p>No files available for this project.</p>
{% endif %}

Can anyone tell me, how to display this?

1 Like

Hello @matsbeckman
You can try this code.

{% assign projectFiles = metafields.projects.files %}

{% if projectFiles.size > 0 %}
  
    {% for file in projectFiles %}
      - {% if file.filename contains '.jpg' or file.filename contains '.jpeg' or file.filename contains '.png' %}
          
          {% else %}
            {{ file.filename }}
          {% endif %}
      
    {% endfor %}
  

{% else %}
  

No files available for this project.

{% endif %}

Hi @ZestardTech

Thanks for your help but it did not work.

I can display an image using “One file”-option in the File field in the Metaobject:


  {% if project.files %}
    
  {% endif %}

but when I Chose “List of files” in the Metaobject field, I can’t find a solution to display the images.