Share » Learn » eZ Publish » How to Import and Export RSS Feeds

How to Import and Export RSS Feeds

Wednesday 20 August 2008 12:14:00 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Now that the RSS import has been configured and runs properly, we must display the new objects on our site. Here, we will assume that you want to display the newest items in a sidebar, showing the titles, short descriptions, and with links to the original articles:

Display of imported RSS feed

If you have other uses in mind, remember that these are now normal eZ Publish objects, meaning that you can use all of the usual eZ Publish template and display logic available.

Line view template for "RSS Item" nodes

First, we need to configure the override rule, then we can create the template to display our imported news items.

Editing the override rule configuration file (override.ini)

In order to instruct eZ Publish to use our to-be-created override template, we must edit the override.ini.append.php file for the public siteaccess, located at /settings/siteaccess/public_site/override.ini.append.php.

(Replace “public_site” with the name of your public siteaccess.)

Add the following entry to the override file:

[line_rss_item]
Source=node/view/line.tpl
MatchFile=line/rss_item.tpl
Subdir=templates
Match[class_identifier]=rss_item

Creating the line view template

The next step is to create the template file specified in the new override entry. The template file will need to be located in a design directory corresponding to the override entry. For sites that use the Website Interface, the location in which to place the template would be /extension/ezwebin/design/ezwebin/override/templates/line/rss_item.tpl.

(Alternatively, you would create a separate design extension to hold all of your custom templates. This is beyond the scope of this article.)

The code for our example line view template for the "RSS Item" object is as follows:

{* RSS Item - Line view *}

<div class="content-view-line">
   <div class="class-rss-item">

       <h4><a href={$node.data_map.link.content} target="_blank">{$node.data_map.title.content|wash()}
 </a></h4>
      {if $node.data_map.description.has_content}
      <div class="attribute-short">
       {attribute_view_gui attribute=$node.data_map.description} 
 ({attribute_view_gui attribute=$node.data_map.rss_source})
       </div>
      {/if}

   </div>
</div>

Although it is left out of the template above, it is also possible to add the date and time the RSS item was published on the source website, by displaying the value of our "Publication Date & Time" attribute. This would be achieved by adding an extra line, probably after the line that ends with ".rss_source})":

{attribute_view_gui attribute=$node.data_map.pub_date_time}

Embedding the RSS items in a page

A simple way to add the RSS feed to the site is to include its folder as an embedded object on, say, the site’s homepage. The following description assumes that the homepage is an eZ Publish "Frontpage" object.

First, log in to either the Administration Interface or Website Interface and open the Object Edit Interface for the frontpage. In the right column section, click the Insert object icon.

Embed button

In the modal dialog that appears, click the Add existing button, then select the folder that contains your imported RSS items. Assign the "Class" property and the limit for the number of RSS items to show, as per your needs.

Embed properties

Finally, click the OK button to close the modal dialog, then click the Send for publishing button to save the changes. You have now successfully completed the RSS import steps! The feed items will display as shown at the top of this page, and the list will automatically be updated whenever new items are imported from the source site.

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)