<p><code>entry.tableHandle</code> is an array of all of the rows, and each row is an array with keys that are the column names and values that are the column values <strong>AND</strong> keys that are <code>col1</code>, <code>col2</code>, etc. and values that are the column values.</p>

<p>So you can do <code>entry.tableHandle[0]|keys</code> to get the keys, <code>entry.tableHandle[0]|keys|length</code> to get the number of keys, and finally <code>(entry.tableHandle[0]|keys|length)/2</code> to get the number of columns.</p>

<p>You will want to check first that there is a row in the table - this won't work if there is no row <code>0</code>.</p>

CC BY-SA 4.0
2018-09-01T01:01:11.123Z
2018-09-01T01:01:11.123Z
Marion Newlevant
<p>Is there a way to return the number of columns in a table?</p>

<p>I tried {{ entry.tableHandle | length }} but this seems to return the number of rows rather than columns.</p>

<p>I've got a site with a couple of tables and I'm trying to output the number of columns in a given table to use for my CSS responsive column width.</p>

<p>I.E. If table was 2 columns, it would output a 2 and I would use that to set column width to 50% etc...</p>

<templating>
Is there a way to return the number of columns in a table?
# Is there a way to return the number of columns in a table?

(Asked by: username_0 on 2018-09-01)

Is there a way to return the number of columns in a table?

I tried {{ entry.tableHandle | length }} but this seems to return the number of rows rather than columns.

I've got a site with a couple of tables and I'm trying to output the number of columns in a given table to use for my CSS responsive column width.

I.E. If table was 2 columns, it would output a 2 and I would use that to set column width to 50% etc...

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2018-09-01. Score: 1

`entry.tableHandle` is an array of all of the rows, and each row is an array with keys that are the column names and values that are the column values **AND** keys that are `col1`, `col2`, etc. and values that are the column values.

So you can do `entry.tableHandle[0]|keys` to get the keys, `entry.tableHandle[0]|keys|length` to get the number of keys, and finally `(entry.tableHandle[0]|keys|length)/2` to get the number of columns.

You will want to check first that there is a row in the table - this won't work if there is no row `0`.


---

