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:
<table>
{% for row in table %}
<tr>
{% for data in row %}
<td>{{ data }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
Outputting table content like this:
{% for row in table %}
{{ dump(row) }}
{% endfor %}
shows me that each row has double entries:
array(6) {
["col1"]=> string(7) "Hamburg"
["col2"]=> string(7) "1730000"
["col3"]=> string(7) "2600000"
["city"]=> string(7) "Hamburg"
["population"]=> string(7) "1730000"
["urbanPopulation"]=> 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?