Symfony 在Twig中列出RSS源中的项目
正在尝试从博客rss源中列出项目。我添加了以下控制器:Symfony 在Twig中列出RSS源中的项目,symfony,twig,Symfony,Twig,正在尝试从博客rss源中列出项目。我添加了以下控制器: /** * @Route("/rss", name="rss", * options={"sitemap" = true} * ) */ public function rss(){ $rss = simplexml_load_file('https://somesite.wordpress.com/feed'); return $th
/**
* @Route("/rss", name="rss",
* options={"sitemap" = true}
* )
*/
public function rss(){
$rss = simplexml_load_file('https://somesite.wordpress.com/feed');
return $this->render('default/rss-reader.html.twig', array(
'rss' => $rss,
));
}
在我的小树枝模板中包含以下内容:
{% for item in rss %}
{{ item.item.title }}
{{ item.item.link }}
{% endfor %}
我以前只有item.title,但后来它显示了博客站点的标题,而不是每个博客的标题。当我使用它时,它只显示第一篇文章,不会继续 simplexml\u load\u file()返回一个simplexmlement对象
因此,这取决于XML结构,RSS提要可以是:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Mon site</title>
<description>Ceci est un exemple de flux RSS 2.0</description>
<lastBuildDate>Sat, 07 Sep 2002 00:00:01 GMT</lastBuildDate>
<link>http://www.example.org</link>
<item>
<title>Actualité N°1</title>
<description>Ceci est ma première actualité</description>
<pubDate>Sat, 07 Sep 2002 00:00:01 GMT</pubDate>
<link>http://www.example.org/actu1</link>
</item>
<item>
<title>Actualité N°2</title>
<description>Ceci est ma seconde actualité</description>
<pubDate>Sat, 07 Sep 2002 00:00:01 GMT</pubDate>
<link>http://www.example.org/actu2</link>
</item>
</channel>
</rss>
蒙斯特
Ceci est联合国通量RSS 2.0示例
2002年9月7日星期六00:00:01 GMT
http://www.example.org
实施1
Ceci是实现的前提
2002年9月7日星期六00:00:01 GMT
http://www.example.org/actu1
实施2
这是第二个现实
2002年9月7日星期六00:00:01 GMT
http://www.example.org/actu2
所以在这里,您尝试循环通过“channel”标记
尝试使用xpath检索
项
标记作为SimpleXMLElement
的数组,以便于导航。关于帖子。我检查了您提供的XML文件,它只包含一篇文章。@Revengence实际的博客是wattdesituse.wordpress.com,试图使用一个通用地址,以免被滥发。