You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Shopify Liquid展示元字段文件列表?代码运行异常求助

解决Shopify file-list类型元字段的文件展示问题

你当前的代码逻辑有误,因为file-list类型的元字段存储的是文件对象数组,不是键值对集合,所以用field | first和field | last无法正确提取文件信息。

直接用下面的代码就能遍历展示所有上传的文件:

{% for file in product.metafields.custom.anleitung %}
  <a href="{{ file.url }}" target="_blank">{{ file.name }}</a>
{% endfor %}

可选扩展展示(按需使用)

如果需要显示更多文件信息,比如文件大小、类型,可以这样写:

{% for file in product.metafields.custom.anleitung %}
  <div style="margin: 8px 0;">
    <span>📄</span>
    <a href="{{ file.url }}" target="_blank" style="margin: 0 8px;">{{ file.name }}</a>
    <span>({{ file.size | filesize }} | {{ file.content_type }})</span>
  </div>
{% endfor %}

关键属性说明

  • file.url:文件的可访问链接
  • file.name:上传时设置的文件名
  • file.size:文件字节大小,搭配filesize过滤器可以转换成友好格式(如KB/MB)
  • file.content_type:文件MIME类型(如application/pdf)

内容的提问来源于stack exchange,提问作者Sebastian Mühlbauer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 05:45:40