govuk-frontend icon indicating copy to clipboard operation
govuk-frontend copied to clipboard

Tables: Consider enabling array iteration in macros

Open paroxp opened this issue 7 years ago • 7 comments

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},
  ]
}) }}

paroxp avatar Mar 02 '18 16:03 paroxp

See also: Digital Marketplace's approach to tables: http://alphagov.github.io/digitalmarketplace-frontend-toolkit/summary-table.html

NickColley avatar Mar 16 '18 10:03 NickColley

See Tijmen's look into this from a Ruby perspective: https://github.com/alphagov/govuk_publishing_components/pull/337

NickColley avatar May 31 '18 13:05 NickColley

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

NickColley avatar Sep 21 '18 15:09 NickColley

Already done.

trang-erskine avatar Oct 27 '21 15:10 trang-erskine

Checked with @36degrees - not sure this was done?

joelanman avatar Jul 13 '22 16:07 joelanman