<p>You don't get table headings with the entry model data (use the <code>dump()</code> function while in dev mode to see yourself). But there's the method <code>getFieldByHandle()</code> that returns a <a href="http://buildwithcraft.com/classreference/models/FieldModel" rel="noreferrer">field model</a> containing info to any field settings.</p>

<h2>This is how you access the headings of a table field</h2>

<h3>Craft 2</h3>

<pre class="lang-none prettyprint-override"><code>{% set field = craft.fields.getFieldByHandle('myTableField') %}

{% for column in field.settings.columns %}
    &lt;li&gt;{{ column.heading }}&lt;/li&gt;
{% endfor %}
</code></pre>

<h3>Craft 3</h3>

<pre class="lang-none prettyprint-override"><code>{% set field = craft.app.fields.getFieldByHandle('myTableField') %}

{% for column in field.settings.columns %}
    &lt;li&gt;{{ column.heading }}&lt;/li&gt;
{% endfor %}
</code></pre>

<p><strong>Table field in Matrix block:</strong></p>

<p>As fields within matrix blocks don't necessarily have unique field handles, you can't use the <code>getFieldByHandle()</code> method to get the field model. Use the unique field ID with the method <code>getFieldById()</code> instead. To look that ID up, open up the source code of the field in the matrix field's field settings. There's a div with the class <code>matrixconfigitem</code> and a data attribute <code>data-id</code>, which is the ID you are looking for.</p>

<p><em>(PS: use the code in your matrix loop for the block type containing your table "sub" field to output in the right place, but it actually works everywhere!)</em></p>

CC BY-SA 3.0
2014-08-26T07:12:39.803Z
what would then be my handle? Tried it with the handle value of the subfield of the blocktype, get an error because the field cannot be found {{ dump(field) }} returns NULL.
Paul
CC BY-SA 3.0
2014-08-26T08:21:35.610Z
Yep sorry. It's a little different with fields in matrix blocks, @paul.
carlcs
CC BY-SA 3.0
2014-08-26T09:32:03.600Z
Thought so, already tried your approach ;)
Paul
CC BY-SA 3.0
2014-08-26T09:36:12.820Z
Does the smily mean the approach works for you? If yes, what about accepting / up voting the answer?
carlcs
CC BY-SA 3.0
2014-08-26T09:53:20.427Z
No, the smily means that I had already tried the approach you mentioned and it didn't work for me. I would have gladly upvoted your answer if it would have been the solution I was after, of course.
Paul
CC BY-SA 3.0
2014-08-26T10:02:32.063Z
Ahh, you mean you tried such an approach before asking the question. Why didn't you mention it?
carlcs
CC BY-SA 3.0
2014-08-26T10:03:19.850Z
@Paul why is `getFieldById()` not working for you? What's the error you get?
carlcs
CC BY-SA 3.0
2014-08-26T10:04:54.903Z
Sorry carlcs, only now I see your edit. Mea culpa. Will try and upvote if it works.
Paul
CC BY-SA 3.0
2014-08-26T07:06:22.710Z
2018-05-01T15:59:05.293Z
2018-05-01T15:59:05.293Z
carlcs
<p>The question says it all.</p>

<p>I have:</p>

<ul>
<li>A Matrix field, with</li>
<li>A subfield with the type table</li>
<li>Two columns within that table of which I want to show the column headers in my template</li>
</ul>

<p>Is that possible and if yes, how?</p>

<templating><matrix><table-field>
Show a table field's column headers in template?
# Show a table field's column headers in template?

(Asked by: username_0 on 2014-08-25)

The question says it all.

I have:

* A Matrix field, with
* A subfield with the type table
* Two columns within that table of which I want to show the column headers in my template

Is that possible and if yes, how?

**Tags:** templating, matrix, table-field

---

## 1 answers

### Answer by username_1 on 2014-08-26. Score: 18 | Accepted answer

You don't get table headings with the entry model data (use the dump() function while in dev mode to see yourself). But there's the method getFieldByHandle() that returns a field model containing info to any field settings.
This is how you access the headings of a table field
Craft 2
{% set field = craft.fields.getFieldByHandle('myTableField') %}

{% for column in field.settings.columns %}
    {{ column.heading }}
{% endfor %}

Craft 3
{% set field = craft.app.fields.getFieldByHandle('myTableField') %}

{% for column in field.settings.columns %}
    {{ column.heading }}
{% endfor %}

Table field in Matrix block:
As fields within matrix blocks don't necessarily have unique field handles, you can't use the getFieldByHandle() method to get the field model. Use the unique field ID with the method getFieldById() instead. To look that ID up, open up the source code of the field in the matrix field's field settings. There's a div with the class matrixconfigitem and a data attribute data-id, which is the ID you are looking for.
(PS: use the code in your matrix loop for the block type containing your table "sub" field to output in the right place, but it actually works everywhere!)

> **Comments:**
> **username_0**: what would then be my handle? Tried it with the handle value of the subfield of the blocktype, get an error because the field cannot be found {{ dump(field) }} returns NULL.  
> **username_1**: Yep sorry. It's a little different with fields in matrix blocks, @paul.  
> **username_0**: Thought so, already tried your approach ;)  
> **username_1**: Does the smily mean the approach works for you? If yes, what about accepting / up voting the answer?  
> **username_0**: No, the smily means that I had already tried the approach you mentioned and it didn't work for me. I would have gladly upvoted your answer if it would have been the solution I was after, of course.  
> **username_1**: Ahh, you mean you tried such an approach before asking the question. Why didn't you mention it?  
> **username_1**: @Paul why is `getFieldById()` not working for you? What's the error you get?  
> **username_0**: Sorry carlcs, only now I see your edit. Mea culpa. Will try and upvote if it works.  

---

