Hi there, I'm quite new to Silverstripe and really at the initial stage of poking around and getting a feel of how Sapphire hangs together.
So I've done a bit of the tutorials and started to play around in a development environment. I set myself the task of making a flexible RSS feed importer I can call from templates. I came across a nice bit of code incorporating SimplePie here: http://www.silverstripe.org/general-questions/show/269733?start=0#post269972 (thanks Mo) and have altered it slightly:
function RSSFeedIn($feed_url = 'http://www.eventfinder.co.nz/feed/events/nelson-tasman/whatson/upcoming.rss', $num_items = 10) {
$output = new DataObjectSet();
include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php'));
$t1 = microtime(true);
$feed = new SimplePie($feed_url, TEMP_FOLDER);
$feed->init();
if($items = $feed->get_items(0, $num_items)) {
foreach($items as $item) {
// Cast the Date
$date = new Date('Date');
$date->setValue($item->get_date());
// Cast the Title
$title = new Text('Title');
$title->setValue($item->get_title());
// Cast the description and strip
$desc = new Text('Description');
$desc->setValue(strip_tags($item->get_description()));
$output->push(new ArrayData(array(
'Title' => $title,
'Date' => $date,
'Link' => $item->get_link(),
'Description' => $desc
)));
}
return $output;
}
}
I can call this via the template like so:
<h3>Upcoming Events</h3>
<ul>
<% control RSSFeedIn %>
<li>
<a href="$Link">$Date - $Title</a>
</li>
<% end_control %>
</ul>
And it works but I expected to be able to call it like this:
<% control RSSFeedIn('http://www.eventfinder.co.nz/feed/events/nelson-tasman/whatson/upcoming.rss',10) %>
Which doesn't work.
I've spent the past half hour searching the Silverstripe Forums/ documentation but haven't found anything which clearly explains what I need to do to make this work so I thought I'd put it out there.
Thanks in advance
Tama