<p>It looks a bit awkward, but to append items to an array you have to use Twig's <a href="http://twig.sensiolabs.org/doc/filters/merge.html" rel="nofollow"><code>merge</code></a> filter, merging the <code>feeds_array</code> with itself for each new item. Here's how I'd do it if you need different logic for each feed:</p>

<pre><code>{% set feeds_array = [] %}

{% for node in craft.feedme.feed(my_rssfeed) %}
    {% set feeds_array = feeds_array|merge([{ title: node.title }]) %}
{% endfor %}

{% for node in craft.feedme.feed(my_otherfeed) %}
    {% set feeds_array = feeds_array|merge([{ title: node.whateverField }]) %}
{% endfor %}

{% for post in feeds_array %}
    {{ post }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-10-21T13:15:32.967Z
Great! That looks good :) I've managed to get it working somewhat. But I haven't gotten to the other feed yet, will use the merge filter when I do! Thanx!
Kenny Bones
CC BY-SA 3.0
2015-10-21T12:36:08.820Z
2015-10-21T12:36:08.820Z
Mike Pepper
<p>I'm relatively new to Twig and PHP in general, so please don't shoot me just yet for asking stupid questions!</p>

<p>Basically, I've got several feeds from RSS to Facebook and Twitter. And I need to merge all of these into a custom array so I can make sure all fields match. I'm gonna output all these later, after sorting them by their published date. </p>

<p>But how do I get started with this thing? Create an empty array first, and then loop through the feeds and push each post into the array? How do I name the fields? This is what I have so far:</p>

<pre><code>{% set feeds_array = [] %}

{% set feed = craft.feedme.feed(my_rssfeed) %}

{% for node in feed %}
    {% set feeds_array = {'title': node.title} %}
{% endfor %}

{% for post in feeds_array %}
    {{post}}
{% endfor %}
</code></pre>

<p>Is this the way to go about this?</p>

<array><feed><plugin-feedme>
Add several feeds into an array
# Add several feeds into an array

(Asked by: username_0 on 2015-10-21)

I'm relatively new to Twig and PHP in general, so please don't shoot me just yet for asking stupid questions!
Basically, I've got several feeds from RSS to Facebook and Twitter. And I need to merge all of these into a custom array so I can make sure all fields match. I'm gonna output all these later, after sorting them by their published date. 
But how do I get started with this thing? Create an empty array first, and then loop through the feeds and push each post into the array? How do I name the fields? This is what I have so far:
{% set feeds_array = [] %}

{% set feed = craft.feedme.feed(my_rssfeed) %}

{% for node in feed %}
    {% set feeds_array = {'title': node.title} %}
{% endfor %}

{% for post in feeds_array %}
    {{post}}
{% endfor %}

Is this the way to go about this?

**Tags:** array, feed, plugin-feedme


---

## 1 answers

### Answer by username_1 on 2015-10-21. Score: 2 | Accepted answer

It looks a bit awkward, but to append items to an array you have to use Twig's merge filter, merging the feeds_array with itself for each new item. Here's how I'd do it if you need different logic for each feed:
{% set feeds_array = [] %}

{% for node in craft.feedme.feed(my_rssfeed) %}
    {% set feeds_array = feeds_array|merge([{ title: node.title }]) %}
{% endfor %}

{% for node in craft.feedme.feed(my_otherfeed) %}
    {% set feeds_array = feeds_array|merge([{ title: node.whateverField }]) %}
{% endfor %}

{% for post in feeds_array %}
    {{ post }}
{% endfor %}

> **Comments:**
> **username_0**: Great! That looks good :) I've managed to get it working somewhat. But I haven't gotten to the other feed yet, will use the merge filter when I do! Thanx!  

---

