Table Maker

Let your users define their own table columns

Templating Tables #

There are two ways you can go about templating a table: use the built-in html output or access the column and row data directly to code your own.

Automatic table output #

This will simply output a valid html table:

{{ entry.myTableField.table }}

Code your own #

Should you want more control over the output you can just access the column and row data directly instead using {{ entry.myTableField.columns }} and {{ entry.myTableField.rows }}.

Here is an example of how you might do just that:

<table>

  <thead>
    <tr>
    {% for col in entry.myTableField.columns %}
      <th align="{{ col.align }}" width="{{ col.width }}">{{ col.heading }}</th>
    {% endfor %}
    </tr>
  </thead>

  <tbody>
    {% for row in entry.myTableField.rows %}
    <tr>
    {% for cell in row %}
      <td align="{{ entry.myTableField.columns[loop.index0].align }}">{{ cell }}</td>
    {% endfor %}
    </tr>
  {% endfor %}
  </tbody>

</table>

Note that when looping rows you can use the current loop index to find the appropriate alignment value for that column.