<p>Solved by putting the event object into an array using square brackets.</p>

<pre><code>{% set todaysEvents = todaysEvents|merge([event]) %}
</code></pre>

CC BY-SA 3.0
2014-10-22T16:30:45.043Z
2014-10-22T16:30:45.043Z
Clive Portman
<p>The merge filter only works with 2 arrays (or 2 hashes), not with an array and an object. I think that the <code>event</code> you are trying to add is not an array, it is a single event (Entry Model). You might try adding the event using <code>[ event ]</code>.</p>

<pre><code>{% set todaysEvents = todaysEvents|merge([event]) %}
</code></pre>

CC BY-SA 3.0
2014-10-22T16:29:23.893Z
Sorted. Use square brackets to create the array instead.
Clive Portman
CC BY-SA 3.0
2014-10-22T16:31:28.177Z
I updated the answer.
Douglas McDonald
CC BY-SA 3.0
2014-10-22T16:34:33.823Z
Thanks Douglas. We got there about the same time. I've removed my comment about curly brackets as they're no longer in the answer.
Clive Portman
CC BY-SA 3.0
2014-10-22T16:37:08.863Z
Glad you got it sorted! Those things can be incredibly frustrating. Been there ;)
Douglas McDonald
CC BY-SA 3.0
2014-10-22T16:08:11.620Z
2014-10-22T16:30:11.760Z
2014-10-22T16:30:11.760Z
Douglas McDonald
<p>I'm trying to loop through some entries and if they fulfil a certain condition push them into another array of entries.</p>

<pre><code>{% set todaysEvents = []
{# GET TODAY'S ONE-OFF EVENTS #}
{% set todaysOneOffEvents = craft.entries.section('events').eventDate('= '~today | date("Y-m-d")).find() %}

{# ADD TODAY'S ONE-OFF EVENTS TO TODAY'S EVENTS #}
{% set todaysEvents = todaysEvents|merge(todaysOneOffEvents) %}
{# WORKING BEAUTIFULLY #}       

{# FOR MULTI-DAY EVENTS THE DATES ARE IN A MATRIX FIELD, SO WE CAN'T FILTER USING CRAFT.ENTRIES #}
{# INSTEAD, WE HAVE TO FILTER EVERY ENTRY IN EVENTS WHICH USE THE MULTI-DAY ENTRY TYPE #}
{% for event in craft.entries.section('events').type('eventWithMultipleDays').find() %}
    {# NOW FIND ONLY ENTRIES WITH A MATRIX BLOCK CONTAINING TODAY'S DATE #}
    {% for date in event.dates if date.multiDate == today | date("Y-m-d") %}
        {# CORRECTLY IDENTIFIES ENTRY AS HAVING TODAY'S DATE IN A MATRIX BLOCK #}
        {# SO NOW WE ADD IT TO TODAYSEVENTS ARRAY #}
        {% set todaysEvents = todaysEvents|merge(event) %}
        {# ERROR: THE MERGE FILTER ONLY WORKS WITH ARRAYS OR HASHES #}      
    {% endfor %}
{% endfor %}
</code></pre>

<p>What go on? See the error in the last comment. How do I pass only these filtered entries into todaysEvents array?</p>

CC BY-SA 3.0
2014-10-22T15:51:46.807Z
I'm trying to do a similar thing right now, looking forward to answers to this!
hamishtaplin
<array><merge>
Adding entries to an array, one at a time
# Adding entries to an array, one at a time

(Asked by: username_0 on 2014-10-22)

I'm trying to loop through some entries and if they fulfil a certain condition push them into another array of entries.
{% set todaysEvents = []
{# GET TODAY'S ONE-OFF EVENTS #}
{% set todaysOneOffEvents = craft.entries.section('events').eventDate('= '~today | date("Y-m-d")).find() %}

{# ADD TODAY'S ONE-OFF EVENTS TO TODAY'S EVENTS #}
{% set todaysEvents = todaysEvents|merge(todaysOneOffEvents) %}
{# WORKING BEAUTIFULLY #}       

{# FOR MULTI-DAY EVENTS THE DATES ARE IN A MATRIX FIELD, SO WE CAN'T FILTER USING CRAFT.ENTRIES #}
{# INSTEAD, WE HAVE TO FILTER EVERY ENTRY IN EVENTS WHICH USE THE MULTI-DAY ENTRY TYPE #}
{% for event in craft.entries.section('events').type('eventWithMultipleDays').find() %}
    {# NOW FIND ONLY ENTRIES WITH A MATRIX BLOCK CONTAINING TODAY'S DATE #}
    {% for date in event.dates if date.multiDate == today | date("Y-m-d") %}
        {# CORRECTLY IDENTIFIES ENTRY AS HAVING TODAY'S DATE IN A MATRIX BLOCK #}
        {# SO NOW WE ADD IT TO TODAYSEVENTS ARRAY #}
        {% set todaysEvents = todaysEvents|merge(event) %}
        {# ERROR: THE MERGE FILTER ONLY WORKS WITH ARRAYS OR HASHES #}      
    {% endfor %}
{% endfor %}

What go on? See the error in the last comment. How do I pass only these filtered entries into todaysEvents array?

**Tags:** array, merge

> **Comments:**
> **username_1**: I'm trying to do a similar thing right now, looking forward to answers to this!  

---

## 2 answers

### Answer by username_2 on 2014-10-22. Score: 7 | Accepted answer

The merge filter only works with 2 arrays (or 2 hashes), not with an array and an object. I think that the event you are trying to add is not an array, it is a single event (Entry Model). You might try adding the event using [ event ].
{% set todaysEvents = todaysEvents|merge([event]) %}

> **Comments:**
> **username_0**: Sorted. Use square brackets to create the array instead.  
> **username_2**: I updated the answer.  
> **username_0**: Thanks Douglas. We got there about the same time. I've removed my comment about curly brackets as they're no longer in the answer.  
> **username_2**: Glad you got it sorted! Those things can be incredibly frustrating. Been there ;)  

---

### Answer by username_0 on 2014-10-22. Score: 1

Solved by putting the event object into an array using square brackets.
{% set todaysEvents = todaysEvents|merge([event]) %}


---

