tablerow
Generates HTML table rows for every item in an array.
The tablerow tag must be wrapped in HTML <table> and </table> tags.
Every tablerow loop has an associated tablerowloop object with information about the loop.
Every tablerow loop has an associated tablerowloop object with information about the loop.
Tip: Every <code>tablerow</code> loop has an associated <a href="/docs/api/liquid/objects/tablerowloop"><code>tablerowloop</code> object</a> with information about the loop.
Syntax
The current item in the array.
The array to iterate over.
The expression to render.
Code
<table>
{% tablerow product in collection.products %}
{{ product.title }}
{% endtablerow %}
</table>Data
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}Output
Output
<table>
<tr class="row1">
<td class="col1">
Draught of Immortality
</td><td class="col2">
Glacier ice
</td><td class="col3">
Health potion
</td><td class="col4">
Invisibility potion
</td></tr>
</table>tablerow tag parameters
cols
Syntax
You can define how many columns the table should have using the cols parameter.
Code
<table>
{% tablerow product in collection.products cols: 2 %}
{{ product.title }}
{% endtablerow %}
</table>Data
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}Output
Output
<table>
<tr class="row1">
<td class="col1">
Draught of Immortality
</td><td class="col2">
Glacier ice
</td></tr>
<tr class="row2"><td class="col1">
Health potion
</td><td class="col2">
Invisibility potion
</td></tr>
</table>limit
Syntax
You can limit the number of iterations using the limit parameter.
Code
<table>
{% tablerow product in collection.products limit: 2 %}
{{ product.title }}
{% endtablerow %}
</table>Data
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}Output
Output
<table>
<tr class="row1">
<td class="col1">
Draught of Immortality
</td><td class="col2">
Glacier ice
</td></tr>
</table>offset
Syntax
You can specify a 1-based index to start iterating at using the offset parameter.
Code
<table>
{% tablerow product in collection.products offset: 2 %}
{{ product.title }}
{% endtablerow %}
</table>Data
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}Output
Output
<table>
<tr class="row1">
<td class="col1">
Health potion
</td><td class="col2">
Invisibility potion
</td></tr>
</table>range
Syntax
Instead of iterating over specific items in an array, you can specify a numeric range to iterate over.
You can define the range using both literal and variable values.
You can define the range using both literal and variable values.
Note: You can define the range using both literal and variable values.
Code
<table>
{% tablerow i in (1..3) %}
{{ i }}
{% endtablerow %}
</table>
{%- assign lower_limit = 2 -%}
{%- assign upper_limit = 4 -%}
<table>
{% tablerow i in (lower_limit..upper_limit) %}
{{ i }}
{% endtablerow %}
</table>Output
Output
<table>
<tr class="row1">
<td class="col1">
1
</td><td class="col2">
2
</td><td class="col3">
3
</td></tr>
</table><table>
<tr class="row1">
<td class="col1">
2
</td><td class="col2">
3
</td><td class="col3">
4
</td></tr>
</table>tablerowloopobjectobject
Information about a parent tablerow loop.
Properties
Returns
trueif the current column is the first in the row. Returnsfalseif not.Returns
trueif the current column is the last in the row. Returnsfalseif not.Returns
trueif the current iteration is the first. Returnsfalseif not.
Example
{
"col": 1,
"col0": 0,
"col_first": true,
"col_last": false,
"first": true,
"index": 1,
"index0": 0,
"last": false,
"length": 5,
"rindex": 5,
"rindex0": 4,
"row": 1
}