Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

RSS stylesheet implementation


Go to End


3 Posts   1638 Views

Avatar
employboy

Community Member, 9 Posts

11 March 2011 at 5:40am

Hello there, after looking through documentation for the RSSFeed object I've discovered a glaring inadequacy. Basically I'd like to add a style sheet to my rss feed for chrome uses, for whom feed content isn't identified as being RSS (at least not in version 2.0).

In case you don't know what I mean, take a look at this link:

http://interglacial.com/~sburke/stuff/pretty_rss.html

Under the heading - The XMLCSS Approach

You can see it's just one line that I'm trying to include but RSSFeed.php is such that I can't easily see anyway to extend it to allow me to include this line. Here's hoping someone reading this has some idea.

Thanks chaps.

Avatar
Willr

Forum Moderator, 5523 Posts

11 March 2011 at 5:39pm

You can see it's just one line that I'm trying to include but RSSFeed.php is such that I can't easily see anyway to extend it to allow me to include this line. Here's hoping someone reading this has some idea.

Could you simply subclass RSSFeed and override the specific function you want to. Then in your project code you can create a new instance of your class rather than RSSFeed.

If you want to override the RSS feed created inside a module (like blog or forum) then you could use Object::useCustomClass('RSSFeed', 'MyRSSFeed') so that any instance of RSSFeed is changed to MyRSSFeed. You may need to check that they use Object::create('RSSFeed') to make the object - if they don't then update the code and submit patches to the respective modules.

Avatar
employboy

Community Member, 9 Posts

26 March 2011 at 3:40am

Thanks Willr, that's exactly what I ended up doing, works a charm except that it was difficult getting the xml headers in for chrome to recognise.

Class RssStyled Extends RSSFeed{
	function feedContent(){
		$prevState = SSViewer::get_source_file_comments();
		SSViewer::set_source_file_comments(false);
		$content = str_replace(' ', ' ', $this->renderWith('RSSFeedStyled'));
		
		SSViewer::set_source_file_comments($prevState);
		
		return $content;
	}
}

Thanks very much for your help.