Plone 3 RSS

modifying the RSS output

After looking at the Planet Plone RSS output, I realized that the default Plone 3 RSS output wasn't really to my liking nor was it what most of Planet Plone's RSS looks like.  Specifically, including only the description and not the body is too terse for my tastes.

I found a few pieces of documentation about changing this:

all of which are out of date but the general idea is pretty easy to follow.  So I customized (gasp!) /portal_skins/plone_templates/rss_template and changed a couple of things.  Note that for some reason rss_template.pt has this incredibly long line which is where most of the changes occur.  I'm not sure why the line might need to be so long so I left it long in my customizations but out of kindness to reading and layout, I've broken them up here.

To include the body in the RSS output I changed the following:

<description tal:content="obj_item/Description">Description</description>


to:

<description tal:content="obj_item/getText">Description</description>


I'm a little nervous about not using a CDATA section as Tom did, but for some reason the resulting RSS seemed to cause most readers to ignore the body text.

I also use short descriptions and even shorter titles, so in the RSS output I wanted to concatenate the two.  To do this I changed the following:

<title tal:content="obj_item/pretty_title_or_id">Title</title>


to:

<title tal:content="string:${obj_item/pretty_title_or_id} - ${obj_item/Description}">Title</title>

 

It seems like the former at least could be made into a configurable option in a control panel for site administrators.  Just a thought.

Update:

I found that the proposed changes above weren't very tolerant of diversity in combination with my use of RSS for tracking comments.  So I further modified rss_template to handle more cases.  Be warned, I shouldn't be doing this as it involves copious use of "python:" in TAL and this is exactly what properly written components in Vice are for.  I put it here only in the manner of confessions.

For the RSS item description I wanted obj.getText if available, or obj.CookedBody if available, or obj.Description() if neither of the first two were available.  I also wanted the title to be a combination of the title and description if either getText or CookedBody were used but just the title otherwise.  I changed the following in rss_template.pt:

<tal:block repeat="brain python: objects">
<item rdf:about="" 
tal:attributes="rdf:about obj_item/getURL|obj_item/absolute_url"
tal:define="obj_item brain/getObject|nocall:brain">
<title tal:content="obj_item/pretty_title_or_id">Title</title>
<link tal:content="obj_item/Identifier">Identifier</link>
<description tal:content="obj_item/Description">Description</description>
<dc:publisher tal:content="obj_item/Publisher">Publisher</dc:publisher>
<dc:creator tal:content="obj_item/Creator">Creator</dc:creator>
<dc:rights tal:content="obj_item/Rights">Rights</dc:rights>
<tal:block tal:repeat="item obj_item/Subject">
<dc:subject tal:content="item">Item</dc:subject>
</tal:block>
<dc:date tal:content="python: obj_item.modified().HTML4()">Modification date</dc:date>
<dc:type tal:content="obj_item/Type">Type</dc:type>
</item></tal:block>

 
to:

<tal:block repeat="brain python: objects">    <item rdf:about=""
  tal:define="obj_item brain/getObject|nocall:brain;
              plone_utils modules/Products/CMFPlone/utils;
              has_text python:plone_utils.base_hasattr(obj_item, 'getText');
              has_body python:plone_utils.base_hasattr(obj_item, 'CookedBody');
              obj_title string:${obj_item/pretty_title_or_id} - ${obj_item/Description};
              obj_title python:(has_text or has_body) and obj_title or obj_item.pretty_title_or_id();
              obj_description python:(has_text and obj_item.getText()) or (has_body and obj_item.CookedBody()) or obj_item.Description();"
  tal:attributes="rdf:about obj_item/getURL|obj_item/absolute_url">
<title tal:content="obj_title">Title</title>
<link tal:content="obj_item/Identifier">Identifier</link>
<description tal:content="obj_description">Description</description>
<dc:publisher tal:content="obj_item/Publisher">Publisher</dc:publisher>
<dc:creator tal:content="obj_item/Creator">Creator</dc:creator>
<dc:rights tal:content="obj_item/Rights">Rights</dc:rights>
<tal:block tal:repeat="item obj_item/Subject">
<dc:subject tal:content="item">Item</dc:subject>
</tal:block>
<dc:date tal:content="python: obj_item.modified().HTML4()">Modification date</dc:date>
<dc:type tal:content="obj_item/Type">Type</dc:type>
</item></tal:block>


Update 2:


Fix long lines because apparently they were messing up the Planet Plone layout.

Updated on 10 February 2008

Imported from Plone on Mar 15, 2021. The date for this update is the last modified date in Plone.

Comments

comments powered by Disqus