govuk-frontend
govuk-frontend copied to clipboard
Tables: Consider enabling array iteration in macros
What
We've got an use case, where we'd like to pass some data into the template without pre-processing it to fit the table macro.
Our use case using pure HTML:
<table>
{% for product in products %}
<tr>
<td>{{ product.name }}</td>
<td>{{ product.description }}</td>
<td>{{ product.price }}</td>
</tr>
{% endfor %}
</table>
What we'd like to be able to do when using macros:
{{ govukTable({
"firstCellIsHeader": true,
"head":[
{"text":"Name"},
{"text":"Description"},
{"text":"Price"}
],
"data": products,
"rows": [
{"text": product.name},
{"text": product.description},
{"text": product.price},
]
}) }}
See also: Digital Marketplace's approach to tables: http://alphagov.github.io/digitalmarketplace-frontend-toolkit/summary-table.html
See Tijmen's look into this from a Ruby perspective: https://github.com/alphagov/govuk_publishing_components/pull/337
Another look into how our tables are being integrated into GOV.UK Publishing Components: https://github.com/alphagov/govuk_publishing_components/pull/531/files#r219539033
Already done.
Checked with @36degrees - not sure this was done?