8

Do you only have to build the .rss template file and then you use that URL for your RSS feed? Based on the documentation at hand, that's what it seems like.

I'm attempting to parse an RSS feed using the Google Feed API (https://developers.google.com/feed/) and it's having issues reading the output - so I just want to see if anyone else out there is using RSS in Craft so I can see their output vs mine. When I view mine, it doesn't look like a traditional xml output.

  • I am facing issues to read external RSS feed which is <rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0"> If I create a plain php file with the parsing code, it works fine and returns me the array of feed, but if I put it in plugin controller, it is giving me an empty array. So if anyone has any clues, or reference, please give me. I am trying to achieve it since 4 days now. – Himanshu Upadhyay Oct 29 '18 at 6:22
17

Here's the boilerplate I've been using for RSS feed templates. I just name the file rss.html and call it a day.

This assumes a channel is set up with a description and title field.

{% header "Content-Type: application/rss+xml" %}
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

{% set rss = craft.entries({ section: 'yourChannel' }) %}

<channel>
  <title>Title Your RSS Feed</title>
  <link>http://www.yourlink.com/</link>
  <description>Enter a description here</description>
  <language>en-us</language>
  <atom:link href="{{ url() }}" rel="self" type="application/rss+xml" />

  {% for item in rss %}
  <item>
    <title>{{ item.title }}</title>
    <link>{{ item.url() }}</link>
    <description>{{ item.description }}</description>
    <pubDate>{{ item.postDate.rfc2822() }}</pubDate>
    <guid>{{ item.url() }}</guid>
  </item>
  {% endfor %}
</channel>

</rss>
| improve this answer | |
  • 1
    In other locales than english, date('r') seems to be translated and no longer results in a valid RSS feed — use item.postDate.rfc2822() instead. – Avant la lettre Mar 12 '15 at 10:47
  • I have used that plugin but confused how to use it and add field. us-cert.gov/ncas/all.xml this is what i want to extract – Dinesh Saini Mar 30 '16 at 6:33
  • Make sure to use the escape filter on whatever you're plugging in to the description field: {% set description = description|e %}, because RSS feeds can break with stuff like &nbsp; that appear in rich text field. – 4midori Oct 17 '16 at 16:32
3

I just used {% header %} and changed it to application/xml instead of application/rss+xml and got the result I was expecting.

| improve this answer | |
2

I made an article about RSS feed template component for Craft CMS - you can read it here:

http://craftsnippets.com/articles/rss-feed-template-component-for-craft-cms

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.