1

フロントページ製品のコレクションをループしてテーブルを生成しています。最後の行では、最初のテーブル セルに静的コンテンツを配置する必要があります。私はそれを行うことができましたが、何らかの理由で、それを行った後にループが停止します。誰かが理由を知っていますか?

  {% 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/

4

1 に答える 1

2

tablerowloop.lastテーブルの最後のセル(つまり、コレクションの最後の積)に対してのみtrueを返し、最後の行に対しては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 %}
于 2012-11-02T05:38:31.227 に答える