场景
需要获取产品所有图片的第一张
图片地址需要自己组成
变量:
product.metafields.custom_fields.path_360
值为 https://360-gemstone-jewellery.kalosgem.com/jewellery/G2522-1.667ct-ruby-ring
需要路径
https://360-gemstone-jewellery.kalosgem.com/jewellery/G2522-1.667ct-ruby-ring/G2522-1.667ct-ruby-ring-small-1.jpg 即后面需要拼接 变量/截取的最后一位 加上 -1-small.jpg
实现
先对 https://360-gemstone-jewellery.kalosgem.com/jewellery/G2522-1.667ct-ruby-ring
进行 split('/')
{% assign path_360_Arr = product.metafields.custom_fields.path_360 | split: "/" %}
拼接
.last
获取被split拆分成数组的 最后一项
{%- capture first_image_path -%}
{{ product.metafields.custom_fields.path_360 }}/{{ path_360_Arr.last }}-small-1.jpg
{%- endcapture -%}
有的不需要 small的 则替换为 medium 类型
{%- assign preview_image = first_image_path | replace: "-small-1.jpg" ,"-medium-1.jpg" -%}
注: {%- xxx -%} 让 xxx不带换行 默认 带换行
https://liquid.bootcss.com/filters/replace/
tmd烦死😡破模版语法