Start Matrix loop from item that contains todays day I have a Matrix block weeklyMenuItems, each item in the block has a dropdown with days of the week (Monday, Tuesday etc). Each entry will have a Matrix block with 7 items, matching the 7 days of the week.

In the template, I would like to start the loop from todays day but still include previous days in the loop, at the end. So, according to the example, whichever item.dayOfTheWeek matches {{ now|date('l') }}.

For instance, if today's day is Wednesday, the loop will output...


Wednesday
Thursday
Friday
Saturday
Sunday
Monday
Tuesday


Here is part of my code, the entries that are being looped are from an entries field of another channel menuSection but I don't think that matters in this instance.

{% for entry in craft.entries.section('menuSection').find() %}

    {% for menuItem in entry.menuEntries %}

        &lt;h2&gt;{{ menuItem.title }}&lt;/h2&gt;

        &lt;ul&gt;
            {# Matrix blocks #}
            {% for item in menuItem.weeklyMenuItems %}
                &lt;li&gt;
                    &lt;h3&gt;{{ item.dayOfTheWeek }}&lt;/h3&gt;
                    &lt;p&gt;{{ item.itemTitle }}&lt;/p&gt;
                &lt;/li&gt;
            {% endfor %}
        &lt;/ul&gt;

    {% endfor %}

{% endfor %}


Any guidance will be welcomed, let me know if I can clarify anything!

Thanks
Do you really want to start the Matrix loop from the week day offset?  Or do you just want to only start printing when that offset matches.  The former seems like a bit of a micro-optimization.

For the latter, something like this completely untested code should do it:

{% for entry in craft.entries.section('menuSection').find() %}

    {% for menuItem in entry.menuEntries %}

        &lt;h2&gt;{{ menuItem.title }}&lt;/h2&gt;

        &lt;ul&gt;
            {% set offset = false %}

            {# Matrix blocks #}
            {% for item in menuItem.weeklyMenuItems %}

                {% if item.dayOfTheWeek == now|date('l') or offset &gt; 0 }}
                    {% set offset = loop.index0 %}

                    &lt;li&gt;
                        &lt;h3&gt;{{ item.dayOfTheWeek }} - Matched&lt;/h3&gt;
                        &lt;p&gt;{{ item.itemTitle }} - Matched&lt;/p&gt;
                    &lt;/li&gt;
                {% endif %}
            {% endfor %}

            {% if offset == false %}
                {% set offset = 0 %}
            {% endif %}

            {# 2nd pass #}
            {% for item in menuItem.weeklyMenuItems|slice(0, offset) %}
                &lt;li&gt;
                    &lt;h3&gt;{{ item.dayOfTheWeek }} - Matched&lt;/h3&gt;
                    &lt;p&gt;{{ item.itemTitle }} - Matched&lt;/p&gt;
                &lt;/li&gt;
            {% endfor %}
        &lt;/ul&gt;

    {% endfor %}

{% endfor %}