Hello there,
I need a page to display Portable Document Format files and video files in the store for customers to download, but after addition, loop file list, use display Name field, the fields are empty, but use alt to display text. Shop does not support video files modification and renaming
{% assign smart_controllers_files = page.metafields.custom.smart_controllers.value %}
{% if smart_controllers_files %}
{% assign aa_name = field.displayName %}
{% assign file_url = field.url %}
{% for field in smart_controllers_files %}
{{aa_name}}
{% endfor %}
{% else %}
Sorry, No file yet.
{% endif %}
You can download it but it doesn’t show the file name. Why?
Any idea?
Thanks
The issue in your code is that you are assigning the displayName and url variables outside the loop, so they will not dynamically change for each file in the loop. To fix this, you need to move the variable assignments inside the loop. Here’s an updated version of your code:
{% assign smart_controllers_files = page.metafields.custom.smart_controllers.value %}
{% if smart_controllers_files %}
{% for field in smart_controllers_files %}
{% assign aa_name = field.displayName %}
{% assign file_url = field.url %}
{{ aa_name }}
{% endfor %}
{% else %}
Sorry, No file yet.
{% endif %}
Sorry, I just noticed that I put the wrong code, I defined it in the for loop, the method you told me, there is still no content, but change
{% assign aa_name = field.alt%}
and there will be content
The problem is, you can’t add alt to the video, so you have to display it using display Name