2

I'm trying to use the native support for rss and atom as described in the documentation, but it misses some info.

Did anyone got this to work? I'm not even sure how to name my template or what the url is going to be.

I tried the following template names: template.twig.atom template.atom.twig template.atom

I tried requests with atom in the header and .atom postfix. Both without any success.

3

Yeah, so I have a rss.twig file in the root of my template directory.

{% 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('article').limit(10).type('article') %}

<channel>
  <title>My Site Name</title>
  <link>{{ siteUrl }}</link>
  <description>My site description</description>
  <language>en-au</language>
  <atom:link href="{{ url() }}" rel="self" type="application/rss+xml" />

  {% for item in rss %}
  <item>
    <title><![CDATA[{{ item.title|raw }}]]></title>
    <link>{{ item.url() }}</link>
    <description><![CDATA[
    {% for block in item.body %}

  {% if block.type == "text" %}

    {{ block.text }}

  {% elseif block.type == "footnote" %}

    {% include 'blocks/_footnote' %}

  {% elseif block.type == "pullQuote" %}

    {% include 'blocks/_pullquote' %}

  {% elseif block.type == "heading" %}

    {% include 'blocks/_heading' %}

  {% elseif block.type == "image" %}

    {% include 'blocks/_image' %}

  {% elseif block.type == "audio" %}

    {% include 'blocks/_audio' %}

  {% elseif block.type == "video" %}

    {% include 'blocks/_video' %}

  {% endif %}

{% endfor %}]]></description>
    <pubDate>{{ item.postDate.rfc2822() }}</pubDate>
    <guid>{{ item.url() }}</guid>
  </item>
  {% endfor %}
</channel>

</rss>

If I access, http://myurl.com/rss - I get my lovely feed.

  • I've just answered my own question. You can name your file .rss instead of .twig and it automatically sets the Content-Type part. – Roel Oct 21 '15 at 6:35
0

Though this is not a proper answer to the question. If you're unfamiliar with how to use the feeds you may be better off taking a look at the feedMe found plugin here:

https://github.com/engram-design/FeedMe

And building out your templates using that. Could save some time and headaches. Sorry I can't give you further information on using the feeds as seen in the docs.

  • 1
    Thanks, but i am trying to generate a feed instead of importing one. – Roel Oct 20 '15 at 14:52
0

It turns out that you can call the template file directly and it answers by default with the right response headers.

So for example, putting templates named feed.atom and feed.rss in the root of your template folder enables you to call them via /feed.atom and /feed.rss. No need for setting content-type by hand.

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.