Answers.Body: <p>Updated code to output the entire table (headers and data).</p>
  
  <p>Try this: </p>
  
  <pre><code>{% set entry = craft.entries.section('sectionHandle').first %}
  
  {% for block in entry.matrixFieldHandle %}
  
      {% for field in block.getFieldLayout().getFields() %}
  
          {% set type = field.getField().type %}
  
          {% switch type %}
              {% case 'Table' %}
  
                  &lt;h3&gt;{{ field.getField().name }}&lt;/h3&gt;
  
                  &lt;table&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              {% set columns = field.getField().settings.columns %}
                              {% for col in columns %}        
                                  &lt;th&gt;{{ col.heading }}&lt;/th&gt;
                              {% endfor %}
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                              {% set handle = field.getField().handle %}
                              {% set tableData = block[handle] %}
                              {% for row in tableData %}
                                  &lt;tr&gt;
                                      {% for key, col in row if key|slice(0,3) == 'col' %}
                                          &lt;td&gt;{{ col }}&lt;/td&gt;
                                      {% endfor %}
                                  &lt;/tr&gt;
                              {% endfor %}
                      &lt;/tbody&gt;
                  &lt;/table&gt;
  
          {% endswitch %}
  
      {% endfor %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-03T20:32:06.783Z
Answers.Text: Awesome. I will look into inspector. I expected that to be a bit more straight forward than that.
Answers.UserDisplayName: Bill Criswell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-03T21:02:06.020Z
Answers.Text: I updated the answer to output the entire table — headers and data. Now just need to do this for each field type and we've got an auto-matrix builder ;)
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-03T21:15:12.340Z
Answers.Text: If you should happen to write that up let me know! I'll be giving it a shot but you seem more familiar with Craft than I am!
Answers.UserDisplayName: Bill Criswell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-03T19:58:32.143Z
Answers.LastActivityDate: 2015-02-03T20:59:21.510Z
Answers.LastEditDate: 2015-02-03T20:59:21.510Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I'm trying to write a general purpose matrix template and I've come up on a little snag with tables fields. I see no way to get the column header values. </p>
  
  <p>The answer <a href="https://craftcms.stackexchange.com/questions/2148/show-a-table-fields-column-headers-in-template">here</a> mentions <code>craft.fields.getFieldById(block.fieldId)</code> but that doesn't appear to exist according to the documentation, nor did it work properly. </p>
  
  <p>The closest I've gotten is this dirty slice job and that only gives me the ids of the columns. So I can do some string manipulation to get them close to the value but they can be completely different as well.</p>
  
  <pre><code>{% set first = block.table | first %}
  {% set columns = first | keys | slice((first | length) / 2, first | length) %}
  </code></pre>
  
  <p>Any ideas would be helpful!</p>
  
  <p>I'm trying to accomplish this:</p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
      {{ loop through table headers }}
    &lt;/thead&gt;
    &lt;tbody&gt;
      {{ loop through table data }}
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-03T19:10:41.880Z
Comments.Text: Do you mean field names within the matrix? or the column names of a table field within the matrix? See if [this post](http://craftcms.stackexchange.com/a/6936/784) answers your question. As a side note I highly recommend a plugin called 'inspector' for printing out methods and properties of objects (i.e. {{ block|inspect }} will show you all properties).
Comments.UserDisplayName: Douglas McDonald
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-03T19:10:47.083Z
Comments.Text: I waned to get the column headers of these types of fields: http://buildwithcraft.com/docs/table-fields I will check out your link though. .getField() looks to be about what I need.
Comments.UserDisplayName: Bill Criswell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-03T19:26:29.773Z
Comments.Text: I don't seem to be able to get to the column headers through your approach, Douglas.
Comments.UserDisplayName: Bill Criswell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-03T19:27:56.227Z
Comments.Text: one sec. working on it.
Comments.UserDisplayName: Douglas McDonald
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-03T19:41:11.253Z
Comments.Text: Awesome. Thanks Douglas. I think I'm getting some terminology mixed up and losing my path along the documentation way.
Comments.UserDisplayName: Bill Criswell
Tags: <matrix><templating><table>
Title: How do I get the column headers of a table in a matrix?
ThreadText: # How do I get the column headers of a table in a matrix?
  
  (Asked by: username_0 on 2015-02-03)
  
  I'm trying to write a general purpose matrix template and I've come up on a little snag with tables fields. I see no way to get the column header values.
  
  The answer [here](https://craftcms.stackexchange.com/questions/2148/show-a-table-fields-column-headers-in-template) mentions `craft.fields.getFieldById(block.fieldId)` but that doesn't appear to exist according to the documentation, nor did it work properly.
  
  The closest I've gotten is this dirty slice job and that only gives me the ids of the columns. So I can do some string manipulation to get them close to the value but they can be completely different as well.
  
  ```
  {% set first = block.table | first %}
  {% set columns = first | keys | slice((first | length) / 2, first | length) %}
  
  ```
  
  Any ideas would be helpful!
  
  I'm trying to accomplish this:
  
  ```
  <table>
    <thead>
      {{ loop through table headers }}
    </thead>
    <tbody>
      {{ loop through table data }}
    </tbody>
  </table>
  
  ```
  
  **Tags:** matrix, templating, table
  
  > **Comments:**
  > **username_1**: Do you mean field names within the matrix? or the column names of a table field within the matrix? See if [this post](http://craftcms.stackexchange.com/a/6936/784) answers your question. As a side note I highly recommend a plugin called 'inspector' for printing out methods and properties of objects (i.e. {{ block|inspect }} will show you all properties).  
  > **username_0**: I waned to get the column headers of these types of fields: http://buildwithcraft.com/docs/table-fields I will check out your link though. .getField() looks to be about what I need.  
  > **username_0**: I don't seem to be able to get to the column headers through your approach, username_1.  
  > **username_1**: one sec. working on it.  
  > **username_0**: Awesome. Thanks username_1. I think I'm getting some terminology mixed up and losing my path along the documentation way.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-03. Score: 2 | Accepted answer
  
  Updated code to output the entire table (headers and data).
  
  Try this:
  
  ```
  {% set entry = craft.entries.section('sectionHandle').first %}
  
  {% for block in entry.matrixFieldHandle %}
  
      {% for field in block.getFieldLayout().getFields() %}
  
          {% set type = field.getField().type %}
  
          {% switch type %}
              {% case 'Table' %}
  
                  <h3>{{ field.getField().name }}</h3>
  
                  <table>
                      <thead>
                          <tr>
                              {% set columns = field.getField().settings.columns %}
                              {% for col in columns %}        
                                  <th>{{ col.heading }}</th>
                              {% endfor %}
                          </tr>
                      </thead>
                      <tbody>
                              {% set handle = field.getField().handle %}
                              {% set tableData = block[handle] %}
                              {% for row in tableData %}
                                  <tr>
                                      {% for key, col in row if key|slice(0,3) == 'col' %}
                                          <td>{{ col }}</td>
                                      {% endfor %}
                                  </tr>
                              {% endfor %}
                      </tbody>
                  </table>
  
          {% endswitch %}
  
      {% endfor %}
  
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Awesome. I will look into inspector. I expected that to be a bit more straight forward than that.  
  > **username_1**: I updated the answer to output the entire table — headers and data. Now just need to do this for each field type and we've got an auto-matrix builder ;)  
  > **username_0**: If you should happen to write that up let me know! I'll be giving it a shot but you seem more familiar with Craft than I am!  
  
  ---
  
  