<p>You should be able to do something like this:</p>
<pre><code>{% for block in entry.eventSchedule
.eventDate(eventDaySlug)
.collect() 
%}
</code></pre>

CC BY-SA 4.0
2023-05-29T17:13:50.483Z
Excellent. Thank you.
CreateSean
CC BY-SA 4.0
2023-05-29T17:12:00.900Z
2023-05-29T17:12:00.900Z
Mike Mella
<p>I've got an event entry with each day of the event in a matrix field block. The block has a date field eventDate and I've got it set up so each block has a unique page that display with the date in segment_3 of the url in this format 2023-07-01</p>
<p>On that page I want to display the matrix again, but only that days block. I cannot figure out how to call a block where the dateEvent field matches the url segment.</p>
<p>Below works with a conditional but it's also pulling in all matrix blocks, not the single block that we need.</p>
<p>ideally there'd be a way to query a field in the block like this where <code>2023-07-01</code> is the date field value I want to filter by (coming from url segment 3).</p>
<pre><code>{% for block in entry.eventSchedule.eventDate('2023-07-01')collect() %}
  more code here
{% endfor %}
</code></pre>
<p>Current full code</p>
<pre><code>{% set entrySlug = craft.app.request.getSegment('2') %}
{% set eventDaySlug = craft.app.request.getSegment('3') %}
{% set entry = craft.entries.slug(entrySlug).one() %}

{% for block in entry.eventSchedule.collect() %}
  {#
    using a conditional to match the date works
    however still loading in all the other matrix blocks
    ideally we'd be able to filter in the for loop by checking the field value there.
  #}
  {% if block.eventDate|date('Y-m-d') == eventDaySlug %}
    &lt;h3 class=&quot;font-semibold text-green-700&quot;&gt;{{ block.eventTitle }}&lt;/h3&gt;
    &lt;p class=&quot;mb-8&quot;&gt;{{ block.eventDate|date('Y-m-d') }}&lt;/p&gt;
  {% endif %}
{% endfor %}
</code></pre>

<templating><matrix>
Matrix Field - Call block that matches block field value
# Matrix Field - Call block that matches block field value

(Asked by: username_0 on 2023-05-29)

I've got an event entry with each day of the event in a matrix field block. The block has a date field eventDate and I've got it set up so each block has a unique page that display with the date in segment_3 of the url in this format 2023-07-01
On that page I want to display the matrix again, but only that days block. I cannot figure out how to call a block where the dateEvent field matches the url segment.
Below works with a conditional but it's also pulling in all matrix blocks, not the single block that we need.
ideally there'd be a way to query a field in the block like this where 2023-07-01 is the date field value I want to filter by (coming from url segment 3).
{% for block in entry.eventSchedule.eventDate('2023-07-01')collect() %}
  more code here
{% endfor %}

Current full code
{% set entrySlug = craft.app.request.getSegment('2') %}
{% set eventDaySlug = craft.app.request.getSegment('3') %}
{% set entry = craft.entries.slug(entrySlug).one() %}

{% for block in entry.eventSchedule.collect() %}
  {#
    using a conditional to match the date works
    however still loading in all the other matrix blocks
    ideally we'd be able to filter in the for loop by checking the field value there.
  #}
  {% if block.eventDate|date('Y-m-d') == eventDaySlug %}
    {{ block.eventTitle }}
    {{ block.eventDate|date('Y-m-d') }}
  {% endif %}
{% endfor %}

**Tags:** templating, matrix

---

## 1 answers

### Answer by username_1 on 2023-05-29. Score: 2 | Accepted answer

You should be able to do something like this:
{% for block in entry.eventSchedule
.eventDate(eventDaySlug)
.collect() 
%}

> **Comments:**
> **username_0**: Excellent. Thank you.  

---

