public function render($ret = false)
{
if (null === $this->template) {
throw new Exception('Error: The feed item template is not set.');
}
$feed = $this->adapter()->getFeed();
if (!isset($feed['items'])) {
throw new Exception('Error: The feed currently has no content.');
}
$output = null;
// Loop through the items, formatting them into the template as needed, using the proper date format if appropriate.
foreach ($feed['items'] as $item) {
$tmpl = $this->template;
foreach ($item as $key => $value) {
if (strpos($tmpl, '[{' . $key . '}]') !== false) {
if (null !== $this->dateFormat && (stripos($key, 'date') !== false || stripos($key, 'published') !== false)) {
$value = date($this->dateFormat, strtotime($value));
}
$tmpl = str_replace('[{' . $key . '}]', $value, $tmpl);
}
}
$output .= $tmpl;
}
// Return the final output.
if ($ret) {
return $output;
} else {
echo $output;
}
}