gpt4 book ai didi

html - Shopify tablerow 循环提前退出

转载 作者:行者123 更新时间:2023-11-28 13:27:29 25 4
gpt4 key购买 nike

我正在遍历我的首页产品集合并生成一个表格。在最后一行,我需要在第一个表格单元格中放置一些静态内容。我已经能够做到这一点,但由于某种原因,循环在它这样做之后停止了。有谁知道为什么吗?

  {% tablerow product in collections.frontpage.products cols: 2 %}
{% if tablerowloop.col_first and tablerowloop.last %}
<img src="{{'box.png' | asset_url}}">
{% else %}
<div class='featured-product'>
<img src="{{ product.images[1] | product_img_url: 'medium' }}">
<p>{{ product.title }}</p>
</div>
{% endif %}
{% endtablerow %}

这是网站:https://hodkiewicz-zieme-and-hirthe180.myshopify.com/

最佳答案

tablerowloop.last 只为表的最后一个单元格(即集合的最后一个产品)返回 true,而不是最后一行。相反,您需要检查索引是否在集合末尾的 cols 内,如果它是第一列,则它必须是最后一行。

{% tablerow product in collections.frontpage.products cols: 2 %}
{% assign x = tablerowloop.length | minus:2 %}
{% if tablerowloop.col_first and tablerowloop.index > x %}
<img src="{{'box.png' | asset_url}}">
{% else %}
<div class='featured-product'>
<img src="{{ product.images[1] | product_img_url: 'medium' }}">
<p>{{ product.title }}</p>
</div>
{% endif %}
{% endtablerow %}

关于html - Shopify tablerow 循环提前退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13186336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com