Why is this not returning file URL?

Solved

Why is this not returning file URL?

ATVO5
Visitor
1 0 0

Hi, I am trying to list file URLs of products in a collection

 

{% assign tracks = collections.frontpage.products | map: 'metafields.audiodemo.upload' %}
tracks = [
{% for track in tracks %}
"{{ track | file_url }}"{% unless forloop.last %},{% endunless %}
{% endfor %}
]

 

But this returns

trackNames = [ "//website.com/cdn/shop/files/?772", "//website.com/cdn/shop/files/?772", "//website.com/cdn/shop/files/?772" ]

 

However when I do

{% assign firstTrack = collections.frontpage.products.first.metafields.audiodemo.upload | file_url %}
{{ firstTrack }}

 

it returns the URL link for the first, so any reason why getting all the collection URLs are not working?

 

thanks

Accepted Solution (1)

LuffyOnePiece
Shopify Partner
650 93 120

This is an accepted solution.

Hi @ATVO5 ,

 

Try adding below code.

 

{% assign tracks = "" %}
{% for product in collections.frontpage.products %}
  {% assign track = product.metafields.audiodemo.upload | file_url %}
  {% capture tracks %}{{ tracks }}{{ track }}{% if forloop.last %}{% else %},{% endif %}{% endcapture %}
{% endfor %}

trackNames = [{{ tracks }}]

 

Thank you

Sandeep Pangeni
Need help with your store? sandeeppangeni17@gmail.com
For quick response, Contact In WhatsApp +9779867521184

View solution in original post

Replies 2 (2)

LuffyOnePiece
Shopify Partner
650 93 120

This is an accepted solution.

Hi @ATVO5 ,

 

Try adding below code.

 

{% assign tracks = "" %}
{% for product in collections.frontpage.products %}
  {% assign track = product.metafields.audiodemo.upload | file_url %}
  {% capture tracks %}{{ tracks }}{{ track }}{% if forloop.last %}{% else %},{% endif %}{% endcapture %}
{% endfor %}

trackNames = [{{ tracks }}]

 

Thank you

Sandeep Pangeni
Need help with your store? sandeeppangeni17@gmail.com
For quick response, Contact In WhatsApp +9779867521184

Darshanp712
Shopify Partner
138 21 19

Hello @ATVO5, Please try the below code.

 

{% assign tracks = collections.your_collection.products %}
   tracks = [
    {% for track in tracks %}
      {% for image in track.images  %}
         "{{ image | json }}"{% unless forloop.last %},<br>{% endunless %}
      {% endfor %} 
    {% endfor %}
]

 

See output below.

Darshanp712_0-1718099447122.png

 

 

Helpful? then please Like and Accept the Solution.
For any inquiries, please feel free to contact via WhatsApp and Email: sales@dolphinwebsolution.com.
For more information visit our website Dolphin Web Solution.