【问题标题】:How to fetch product image urls on a product page?如何在产品页面上获取产品图片网址?
【发布时间】:2020-04-03 09:44:11
【问题描述】:

我正在为我的 bigcartel 商店构建自定义主题。试图实现一个分享按钮,我想将第一张图片的 URL 插入到分享控件中。如何仅访问第一张图片?谢谢!!

【问题讨论】:

    标签: bigcartel


    【解决方案1】:

    在产品页面上,或者当您有可用的product 变量时 - 您可以使用以下方法检索第一张图片:

    {{ product.image | product_image_url }}

    这里也有记录:

    https://developers.bigcartel.com/api/themes#product

    product.image   Returns the default image of a product.
    product.images  Returns all of the images of a product.
    product.image_count Returns the number of images a product has
    

    【讨论】:

    • 那个比我想出的要容易得多!谢谢!
    【解决方案2】:

    想通了。

    您可能希望启动一个指定 limit 值的 for 循环(见下文)

    {% for image in product.images limit:1 %}
      First image URL: {{ image.url }}
    {% endfor %}
    

    显然你可以通过这种方式遍历任何可用的数组。

    BigCartel documentation找到它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多