Table Row

v1.9.1

生成一个 HTML 表示,上下必须用 <table></table> HTML 标签包裹起来。

基本使用

输入

<table>
{% tablerow product in collection.products %}
{{ product.title }}
{% endtablerow %}
</table>

输出

<table>
<tr class="row1">
<td class="col1">
Cool Shirt
</td>
<td class="col2">
Alien Poster
</td>
<td class="col3">
Batman Poster
</td>
<td class="col4">
Bullseye Shirt
</td>
<td class="col5">
Another Classic Vinyl
</td>
<td class="col6">
Awesome Jeans
</td>
</tr>
</table>

参数

cols

定义表格的列数。

输入

{% tablerow product in collection.products cols:2 %}
{{ product.title }}
{% endtablerow %}

输出

<table>
<tr class="row1">
<td class="col1">
Cool Shirt
</td>
<td class="col2">
Alien Poster
</td>
</tr>
<tr class="row2">
<td class="col1">
Batman Poster
</td>
<td class="col2">
Bullseye Shirt
</td>
</tr>
<tr class="row3">
<td class="col1">
Another Classic Vinyl
</td>
<td class="col2">
Awesome Jeans
</td>
</tr>
</table>

limit

限制迭代次数。

{% tablerow product in collection.products cols:2 limit:3 %}
{{ product.title }}
{% endtablerow %}

offset

从指定的下标处开始循环。

{% tablerow product in collection.products cols:2 offset:3 %}
{{ product.title }}
{% endtablerow %}

range

定义一个用于循环的数字范围。可以用字面量定义范围,也可以用变量定义范围。

<!--variable number example-->

{% assign num = 4 %}
<table>
{% tablerow i in (1..num) %}
{{ i }}
{% endtablerow %}
</table>

<!--literal number example-->

<table>
{% tablerow i in (3..5) %}
{{ i }}
{% endtablerow %}
</table>