简体   繁体   English

将产品集合与Shopify中的静态元素一起输出到表中

[英]Output product collection into a table along with static element in Shopify

I need to output a collection of products into a table on my index page. 我需要将产品集合输出到索引页面上的表中。 What is the best way to do this? 做这个的最好方式是什么? I was looking in the docs and found the tablerow stuff. 我在看文档时发现了tablerow的东西。 The problem is, that products are going to need to come out two at a time, that is there are two images in every row (two different products) and then in the next row are the names. 问题在于,产品将需要一次出现两个,即每行有两个图像(两个不同的产品),然后在下一行是名称。 I did things this way because it was the easiest way to keep everything lined up properly as the image sizes tend to change. 我这样做是因为,这是最简单的方法,可以随着图像尺寸的变化而使所有内容正确对齐。 Also, there's a static element that needs to be output into the table too. 此外,还有一个静态元素也需要输出到表中。 Any advice on this? 有什么建议吗?

Here's the store: 这是商店:

https://hodkiewicz-zieme-and-hirthe180.myshopify.com/ https://hodkiewicz-zieme-and-hirthe180.myshopify.com/

Here's the relevant code: 以下是相关代码:

  <table>
        <tr>
          <td><img src="{{'carb-1.png' | asset_url}}"></td>
          <td><img src="{{'carb-2.png' | asset_url}}"></td>
        </tr>
        <tr>
          <td>1930 Speedster</td>
          <td>1929-1931 Super 8</td>
        </tr>
      <tr>
        <td><img src="{{'carb-3.png' | asset_url}}"></td>
        <td><img src="{{'carb-4.png' | asset_url}}"></td>
      </tr>
      <tr>
        <td>1932 Super 8</td>
        <td>1929-1931 Standard 8</td>
      </tr>
      <tr>
        <td><img src="{{'box.png' | asset_url}}"></td>
        <td><img src="{{'carb-5.png' | asset_url}}"></td>
      </tr>
      <tr>
        <td></td>
        <td>1932 Standard 8</td>
      </tr>
    </table>

At the moment, I'm statically outputting all of the relevant images. 目前,我正在静态输出所有相关图像。

Wrap each image and the associated description in a div and output them together in a single table cell. 将每个图像和相关描述包装在div中,然后将它们一起输出到单个表格单元格中。 That way you can still output everything using the tablerow instruction. 这样,您仍然可以使用tablerow指令输出所有内容。

Furthermore, you can get clever with your static content and render that in the tablerow loop too. 此外,您可以巧妙地使用静态内容,并将其呈现在tablerow循环中。 Use a combination of the row and column identifiers listed on the Shopify Wiki to find the cell you want the static content in, and render that instead of a product when you hit the correct cell. 使用Shopify Wiki上列出行和列标识符的组合来查找您想要静态内容的单元格,并在您单击正确的单元格时呈现该单元格而不是产品。

Your code might look something like this 您的代码可能看起来像这样

  {% tablerow item in items cols: 3 %}
    {% if tablerowloop.col_first &&  tablerowloop.last %}
      <!-- Display static content! -->
    {% else %}
      <div class='table-item'>
        {{item.image}}
        <p>{{item.title}}</p>
      </div>
    {% endif %}
  {% endtablerow %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM