Double storage of values in table-field I'm currently creating some standard templates which should help to find good defaults for matrix output. This is where I stumpled upon the somehow weird structure of table data.

Here's a simplified structure of what I want to build:

&lt;table&gt;
{% for row in table %}
  &lt;tr&gt;
  {% for data in row %}
    &lt;td&gt;{{ data }}&lt;/td&gt;
  {% endfor %}
  &lt;/tr&gt;
{% endfor %}
&lt;/table&gt;


Outputting table content like this:

{% for row in table %}
  {{ dump(row) }}
{% endfor %}


shows me that each row has double entries:

array(6) {
  ["col1"]=&gt; string(7) "Hamburg"
  ["col2"]=&gt; string(7) "1730000"
  ["col3"]=&gt; string(7) "2600000"

  ["city"]=&gt; string(7) "Hamburg"
  ["population"]=&gt; string(7) "1730000"
  ["urbanPopulation"]=&gt; string(7) "2600000"
}


While this might make sense in some cases, I don't get it. Why is this behavior and in which cases could the convention "col1", "col2", etc. make sense?

On first sight, this choice is very unfortunate as it prevents dynamic table output. Sure, you could use hacks like loop.index to target these, but that makes the code very unreadable and ugly.

Does anyone have the same issue with this?
The data is not stored twice in the database. I suspect that craft adds the additional array items when prepping the data, so that they can be referenced by either column number or column title.

But with a little finesse, you might be able to do something like the following, using key, value in the for loop and twig's slice filter:

&lt;table&gt;
    {% for row in entry.myTableFieldHandle %}
        &lt;tr&gt;
            {% for key, data in row if key|slice(0,3) == 'col' %}
                &lt;td&gt;{{ data }}&lt;/td&gt;
            {% endfor %}
        &lt;/tr&gt;
    {% endfor %}
&lt;/table&gt;