Skip to content

RSS

Intro

The WfCmsRssBundle uses the Zend Feed Writer component to generate the RSS feeds. The output of the RSS can be tweaked by adding and using extensions.

Custom extensions

The WfCms automatically registers extensions for Zend Feed Writer based on parameters:

  • wf_rss.extension.__EXTENSION_NAME__.feed - the class for feed
  • wf_rss.extension.__EXTENSION_NAME__.entry - the entry class for feed items
  • wf_rss.extension.__EXTENSION_NAME__.renderer_feed - the renderer class for the feed
  • wf_rss.extension.__EXTENSION_NAME__.renderer_entry - the renderer class for each items

Default extension

WfCms automatically enables the extension with the name of the project. For example, if the wf_cms.bundle.public parameter is XxxCmsBundle, adding the parameter wf_rss.extension.xxx.renderer_entry automatically registers that class as a renderer for the feed's entries.

If an extension should be enabled only in some cases:

  1. Add the parameters for the extension: wf_rss.extension.example.renderer_entry: XXX\Bundle\CmsBundle\...\ExampleRendererEntry

  2. Overwrite the wf_rss.extension_manager.class with a custom class

  3. Check if the extension should be enabled:

    php
    
    class ExtensionManager extends Wf\Bundle\CmsRssBundle\ExtensionManager 
    {
        public function registerExtensions(Symfony\Component\HttpFoundation\Request $request) 
        {
            if ($request->get('example', false)) { //register the `example` extension only if `example` parameter is true in the request
                $this->registerExtension('example');
            }
        }
    }
  4. Implement the ExampleRendererEntry class:

    php
    class ExampleRendererEntry extends Wf\Bundle\CmsRssBundle\Feed\WfCmsFeedExtension\Renderer\BaseEntry
    {
        public function render() {
            $this->addTextNode('example_node', 'value');
        }
    }

Accessing article data

In the entry renderer class, access the underlying data container (the Entry object) with $this->getDataContainer().

All the get methods that don't exist in the Entry class are forwarded to the corresponding PageArticle object. So, if you define a method PageArticle:getSmiles, in the entry renderer you could just:

php
$this->addText('smiles', $this->getDataContainer()->getSmiles());

Helper methods for entry renderer

The BaseEntry class from WfCmsRssBundle exposes some methods to ease dealing with the RSS:

php
$this->addText('text_node', 'text_value', array('attribute' => 'attributeValue'));
php
$nodes = array();
for ($i = 0; $i < 10; $i++) {
    $nodes[] = $this->getTextNode('node_' . $i, 'value_' . $i);
}
$this->addArrayNode('array_node',$nodes, array('attribute' => 'attributeValue'));
php
$this->generateArticleUrl($this->getDataContainer()); //generate the absolute url to this entry's article