Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

API: add api for setting a custom template on a RSS feed.

See initial idea at http://open.silverstripe.org/ticket/6441. Added $template property and corresponding getters / setters for customizing the template used. Added relevant unit test.
  • Loading branch information...
commit f1db65d6b6142af426c2a6b3cc0274643f674824 1 parent 23ed533
@wilr wilr authored
View
27 api/RSSFeed.php
@@ -8,6 +8,7 @@
* @subpackage integration
*/
class RSSFeed extends ViewableData {
+
/**
* Casting information for this object's methods.
* Let's us use $Title.XML in templates
@@ -81,6 +82,11 @@ class RSSFeed extends ViewableData {
protected $etag;
/**
+ * @var string
+ */
+ protected $template = 'RSSFeed';
+
+ /**
* Constructor
*
* @param SS_List $entries RSS feed entries
@@ -203,10 +209,29 @@ function outputToBrowser() {
function feedContent() {
$prevState = SSViewer::get_source_file_comments();
SSViewer::set_source_file_comments(false);
- $content = str_replace(' ', ' ', $this->renderWith('RSSFeed'));
+ $content = str_replace(' ', ' ', $this->renderWith($this->getTemplate()));
SSViewer::set_source_file_comments($prevState);
return $content;
}
+
+ /**
+ * Set the name of the template to use. Actual template will be resolved
+ * via the standard template inclusion process.
+ *
+ * @param string
+ */
+ public function setTemplate($template) {
+ $this->template = $template;
+ }
+
+ /**
+ * Returns the name of the template to use.
+ *
+ * @return string
+ */
+ public function getTemplate() {
+ return $this->template;
+ }
}
/**
View
14 tests/api/RSSFeedTest.php
@@ -43,6 +43,20 @@ function testRSSFeed() {
$this->assertContains('<description>ItemC AltContent</description>', $content);
}
+ public function testRenderWithTemplate() {
+ $rssFeed = new RSSFeed(new ArrayList(), "", "", "");
+ $rssFeed->setTemplate('RSSFeedTest');
+
+ $content = $rssFeed->feedContent();
+
+ $this->assertContains('<title>Test Custom Template</title>', $content);
+
+ $rssFeed->setTemplate('RSSFeed');
+ $content = $rssFeed->feedContent();
+
+ $this->assertNotContains('<title>Test Custom Template</title>', $content);
+ }
+
public function setUp() {
parent::setUp();
Director::setBaseURL('/');
View
6 tests/templates/RSSFeedTest.ss
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
+ <channel>
+ <title>Test Custom Template</title>
+ </channel>
+</rss>
Please sign in to comment.
Something went wrong with that request. Please try again.