2

I think a better way to achieve this would be with Supertable, but for now I'm wondering if there is a way to group the example output

W/C: 27 Aug 2018 {{ block.week }}

1.5 {{ block.totalTime }}

W/C: 27 Aug 2018 {{ block.week }}

2.5 {{ block.totalTime }}

W/C: 27 Aug 2018 {{ block.week }}

3 {{ block.totalTime }}

instead like

W/C: 27 Aug 2018

1.5

2.5

3

so values from the 'number' field {{ block.totalTime }} which share the same value from the 'date' field {{ block.week }} are somehow grouped together?

from the matrix fields in use below:

     {% for block in entry.timeSheet %}

        {% if block.totalTime | length %}

        <strong>W/C: {{ block.week|date('j M Y') }}</strong><br />
        {{ block.totalTime }}
        {% endif %}{{ not loop.last ? '<hr>' }}

     {% endfor %}
2

I think what you're saying is that you only want to output the heading once it's different from the previous heading. So if you have two blocks with the same week, we only show it once.

You can set a variable of week and check that the current block's week (which I've set as tempWeek to keep code cleaner) is the same. If it isn't the same, it means we've changed week so display the title and then set week to be this new week.

{% set week = "" %}
{% for block in entry.timeSheet %}
    {% set tempWeek = block.week|date('j M Y') %}
    {% if tempWeek!=week %}
        <strong>W/C: {{ block.week|date('j M Y') }}</strong><br />
        {% set week = tempWeek %}
    {% endif %}
    {% if block.totalTime | length %}
        {{ block.totalTime }}<br>
    {% endif %}
    {{ not loop.last ? '<hr>' }}
{% endfor %}
1
  • Amazing! thanks – user2569 Aug 28 '18 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.