RSS view


1Presentation

The RSS view allows you to send feeds in RSS format, used in particular to list the content posted on a content site (such as a blog).


2Usage

To use the RSS view, you must define the use of this view. In addition to that, you must assign several template variables:

  • title: (mandatory) Defines the title of the site.
  • description: (mandatory) Defines the description of the site.
  • domain: (mandatory) Defines the domain name of the site.
  • language: (optional) Defines the language of the site (or the language of the content listed in the RSS feed).
  • contact: (optional) Defines the contact email address of the site.
  • copyright: (optional) Copyright information.
  • category: (optional) Category of the site. Blog by default.
  • articles: Defines the list of articles to be listed in the feed. Each element of the list must be an associative array with the following keys:
    • title: (mandatory) Title of the article.
    • url: (mandatory) URL of the article.
    • pubDate: (optional) Publication date in 'YYYY-MM-DD hh:mm:ss' format.
    • abstract: (optional) Summary of the article.
    • author: (optional) Email address of the author.
    • guid: (optional) Unique identifier of the article (use its URL otherwise). It is declared as a permalink only if it is a URL.
    • image: (optional) URL of the article's image.
    • imageType: (optional) Type of the image (jpg, png, gif or webp). jpg by default.
    • categories: (optional) List of categories of the article.

Here is an example of sending data in RSS format:

class ApiController extends \Temma\Web\Controller {
    public function getArticles() {
        $this['domain'] = 'https://mysite.com';
        $this['title'] = 'My super site';
        $this['description'] = 'Blah blah blah blah blah';
        $this['language'] = 'en';
        $this['contact'] = 'contact@mysite.com';
        $this['articles'] = [
            [
                'title'    => 'Happy new year!',
                'url'      => 'https://mysite.com/page/23',
                'pubDate'  => '2000-01-01 00:00:00',
            ],
            [
                'title'    => 'New decade',
                'url'      => 'https://mysite.com/page/734',
                'pubDate'  => '2010-01-01 00:00:00',
            ],
        ];

        // set the used view
        $this->_view('\Temma\Views\Rss');
    }
}
  • Lines 3 to 19: Definition of the data that will be transmitted to the view.
  • Line 22: We specify that the view to use for the outgoing data is the RSS view (and not the usual Smarty view).

Note: The RSS view obviously does not need templates, since it is the PHP data that is directly serialized.

By default, the view sends the Content-Type: application/rss+xml; charset=UTF-8 header. To send another content type, use the controller's _contentType() method or the ContentType attribute.

The received data will look like this:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
    <link>https://mysite.com/</link>
    <title>My super site</title>
    <description>Blah blah blah blah blah</description>
    <language>en</language>
    <managingEditor>contact@mysite.com</managingEditor>
    <webMaster>contact@mysite.com</webMaster>
    <generator>Temma RSS generator 1.0.0</generator>
    <category>Blog</category>
    <item>
        <title>Happy new year!</title>
        <link>https://mysite.com/page/23</link>
        <guid isPermaLink="true">https://mysite.com/page/23</guid>
        <pubDate>Sat, 01 Jan 2000 00:00:00 +0100</pubDate>
    </item>
    <item>
        <title>New decade</title>
        <link>https://mysite.com/page/734</link>
        <guid isPermaLink="true">https://mysite.com/page/734</guid>
        <pubDate>Fri, 01 Jan 2010 00:00:00 +0100</pubDate>
    </item>
</channel>
</rss>
It is also possible to transmit the data to export using the @output template variable containing an associative array with the same keys (domain, title, articles, etc.). If @output is defined, it takes priority.

3Download

If you want the RSS feed to be sent as a downloadable attachment, define a template variable named filename, containing the file name.

Example:

$this['filename'] = 'january.rss';