<p>You can do this by filtering the Matrix field down to just the field block(s) you want using their handle.</p>
<pre><code>{% for entry in craft.entries.section('articles').all() %}
    &lt;item&gt;
        &lt;title&gt;{{ entry.title }}&lt;/title&gt;
        &lt;link&gt;{{ entry.url }}&lt;/link&gt;
        &lt;pubDate&gt;{{ entry.postDate|rss }}&lt;/pubDate&gt;
        &lt;author&gt;{{ entry.author }}&lt;/author&gt;
        &lt;guid&gt;{{ entry.url }}&lt;/guid&gt;
        &lt;description&gt;&lt;![CDATA[
        {% for block in entry.myMatrixField.type('blockTypeHandle').all() %}
             {{ block.textContent|striptags }}
        {% endfor %}
        ]]&gt;&lt;/description&gt;
    &lt;/item&gt;
{% endfor %}
</code></pre>
<p>This example filters a Matrix field down to just the blocks that have a handle of <code>blockTypeHandle</code> within the field, and outputs their content, which in this case is a rich text field with a handle of <code>textContent</code>.</p>

CC BY-SA 4.0
2023-08-30T13:37:18.390Z
Hi Martin , your code makes sense but it doesn't work for me . My matrix field is called innerContent , my block is called innerText and my field is called text . Here is the code I used <description><![CDATA[  {% for block in entry.innerContent.type('innerText').all() %}
                                {{ block.text|striptags }}
                                {% endfor %}
]]></description>. I get a Twig error Variable "entry" does not exist. I have wrapped the code in with the right craft entries tag as the rss outputs correctly if I leave out that matrix block.
bhackett
CC BY-SA 4.0
2023-08-31T09:31:02.307Z
Hmm, that's odd. Is there an `entry` variable available within the `{% for .. in %}` loop? What do you get if you add a `{% dd entry %}` statement inside the loop?
Martin Spain
CC BY-SA 4.0
2023-08-31T10:35:42.180Z
Thanks Martin, got it working. I was using item instead of entry to define the Rss fields. Thanks for your help
bhackett
CC BY-SA 4.0
2023-08-30T08:32:13.347Z
2023-08-30T08:32:13.347Z
Martin Spain
<p>I'm trying to create RSS feed for a site news section, most of it is straight forward to do but I run into an issue with the description section. That content is a sub field in a matrix field along with other subfields like downloads and block quotes.</p>
<p>I have looked extensively, and I haven't found any examples or ideas on how to do this. I can output the matrix field itself in the rss and it gives me a list of all the fieldnames it contains but I can't find a way to output those sub fields into the RSS feed as items.
Thanks for any help</p>

<matrix><rss><xml>
Output matrix field content into a RSS feed
# Output matrix field content into a RSS feed

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

I'm trying to create RSS feed for a site news section, most of it is straight forward to do but I run into an issue with the description section. That content is a sub field in a matrix field along with other subfields like downloads and block quotes.

I have looked extensively, and I haven't found any examples or ideas on how to do this. I can output the matrix field itself in the rss and it gives me a list of all the fieldnames it contains but I can't find a way to output those sub fields into the RSS feed as items.
Thanks for any help

**Tags:** matrix, rss, xml

---

## 1 answers

### Answer by username_1 on 2023-08-30. Score: 1 | Accepted answer

You can do this by filtering the Matrix field down to just the field block(s) you want using their handle.
{% for entry in craft.entries.section('articles').all() %}
    
        {{ entry.title }}
        {{ entry.url }}
        {{ entry.postDate|rss }}
        {{ entry.author }}
        {{ entry.url }}
        
        {% for block in entry.myMatrixField.type('blockTypeHandle').all() %}
             {{ block.textContent|striptags }}
        {% endfor %}
        
    
{% endfor %}

This example filters a Matrix field down to just the blocks that have a handle of blockTypeHandle within the field, and outputs their content, which in this case is a rich text field with a handle of textContent.

> **Comments:**
> **username_0**: Hi Martin , your code makes sense but it doesn't work for me . My matrix field is called innerContent , my block is called innerText and my field is called text . Here is the code I used <description><![CDATA[  {% for block in entry.innerContent.type('innerText').all() %}                                 {{ block.text|striptags }}                                 {% endfor %} ]]></description>. I get a Twig error Variable "entry" does not exist. I have wrapped the code in with the right craft entries tag as the rss outputs correctly if I leave out that matrix block.  
> **username_1**: Hmm, that's odd. Is there an `entry` variable available within the `{% for .. in %}` loop? What do you get if you add a `{% dd entry %}` statement inside the loop?  
> **username_0**: Thanks Martin, got it working. I was using item instead of entry to define the Rss fields. Thanks for your help  

---

