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.
Syntax
The current item in the array.
The array to iterate over.
The expression to render.
<table>
{% tablerow product in collection.products %}
{{ product.title }}
{% endtablerow %}
</table>
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}
Output
tablerow tag parameters
cols
Syntax
You can define how many columns the table should have using the cols
parameter.
<table>
{% tablerow product in collection.products cols: 2 %}
{{ product.title }}
{% endtablerow %}
</table>
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}
Output
limit
Syntax
You can limit the number of iterations using the limit
parameter.
<table>
{% tablerow product in collection.products limit: 2 %}
{{ product.title }}
{% endtablerow %}
</table>
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}
Output
offset
Syntax
You can specify a 1-based index to start iterating at using the offset
parameter.
<table>
{% tablerow product in collection.products offset: 2 %}
{{ product.title }}
{% endtablerow %}
</table>
{
"collection": {
"products": [
{
"title": "Draught of Immortality"
},
{
"title": "Glacier ice"
},
{
"title": "Health potion"
},
{
"title": "Invisibility potion"
}
]
}
}
Output
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.
<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
tablerowloopobject
Information about a parent tablerow
loop.
Properties
Returns
true
if the current column is the first in the row. Returnsfalse
if not.Returns
true
if the current column is the last in the row. Returnsfalse
if not.
{
"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
}