SmartyPie: Feeding the Smarty PHP Template Engine with SimplePie
May 23 2008 10:28 pm | SimplePie
Here’s a little demo showing how to use SimplePie with the Smarty PHP template engine.
<?php
require_once('simplepie.inc');
$feed = new SimplePie('http://simplepie.org/');
$titles = array();
foreach($feed->get_items() as $item)
{
$i['title'] = $item->get_title();
$i['link'] = $item->get_link();
$i['date'] = $item->get_date();
$items[] = $i;
}
require('Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->assign('items', $items);
$smarty->display('index.tpl');
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<ul>
{foreach from=$items key=myId item=i}
<li>
{$i.date} <a href="{$i.link}">{$i.title}</a>
</li>
{/foreach}
</ul>
</body>
</html>



Fred on 15 Jan 2009 at 5:19 pm #
Hello,
Thanks for this post which was of great help for me. I’m still encountering a problem, though… How do I manage to get the embedded video files from the feeds in the Smarty template ? I’ve tried using the get_enclosure() function, but it didn’t work… I’m sure I’m doing something wrong… If you could give me a hint on that, I’d greatly appreciate.
Thanks !
Fred.
Abeon on 23 Jun 2009 at 3:08 pm #
Thanks. I’ve just been looking for this.
Smarty just froze when I tried adding a feed directly.
streetparade on 14 Aug 2009 at 1:33 pm #
Hello very good tutorial; it works perfect, except what aibbon said the get_enclosure.
I dont know how to put that shit in the array