Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T07:12:39.803Z
Answers.Text: 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.
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T08:21:35.610Z
Answers.Text: Yep sorry. It's a little different with fields in matrix blocks, @paul.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T09:32:03.600Z
Answers.Text: Thought so, already tried your approach ;)
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T09:36:12.820Z
Answers.Text: Does the smily mean the approach works for you? If yes, what about accepting / up voting the answer?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T09:53:20.427Z
Answers.Text: 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.
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T10:02:32.063Z
Answers.Text: Ahh, you mean you tried such an approach before asking the question. Why didn't you mention it?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T10:03:19.850Z
Answers.Text: @Paul why is `getFieldById()` not working for you? What's the error you get?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T10:04:54.903Z
Answers.Text: Sorry carlcs, only now I see your edit. Mea culpa. Will try and upvote if it works.
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-26T07:06:22.710Z
Answers.LastActivityDate: 2018-05-01T15:59:05.293Z
Answers.LastEditDate: 2018-05-01T15:59:05.293Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Tags: <templating><matrix><table-field>
Title: Show a table field's column headers in template?
ThreadText: # 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](http://buildwithcraft.com/classreference/models/FieldModel) containing info to any field settings.
  
  ## This is how you access the headings of a table field
  
  ### Craft 2
  
  ```none
  {% set field = craft.fields.getFieldByHandle('myTableField') %}
  
  {% for column in field.settings.columns %}
      <li>{{ column.heading }}</li>
  {% endfor %}
  
  ```
  
  ### Craft 3
  
  ```none
  {% set field = craft.app.fields.getFieldByHandle('myTableField') %}
  
  {% for column in field.settings.columns %}
      <li>{{ column.heading }}</li>
  {% 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, @username_0.  
  > **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**: @username_0 why is `getFieldById()` not working for you? What's the error you get?  
  > **username_0**: Sorry username_1, only now I see your edit. Mea culpa. Will try and upvote if it works.  
  
  ---
  
  