Search code examples
phptemplatesrssfat-free-framework

Create RSS feed with PHP Fat Free Framework?


I am looking for a way to create an RSS feed from a database query using Fat Free Framework.

Does F3 come with this functionality packaged? Or is there any way to create an RSS feed using an F3 template?


Solution

  • Yes, you can do this using the f3 templating engine to output the correct xml, eg:

    rss.template:

    <?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>{{@blog.title}} </title>
        <link>{{@REALM}}</link>
        <description></description>
        <lastBuildDate>{{date(@blog.date.rss)}}</lastBuildDate>
        <language>{{@LANGUAGE}}</language>
        <atom:link href="{{@REALM}}" rel="self" type="application/rss+xml" />
        <repeat group="{{@posts}}" key="{{@key}}" value="{{@post}}">
        <item>
            <title>{{@post->title}} </title>
            <pubDate>{{date(@blog.date.rss, @post->date->sec)}}</pubDate>
            <link>http://studio{{@BASE}}/post/{{@post->_id}}/{{tools::slug(@post->title)}}</link>
            <guid>http://studio{{@BASE}}/post/{{@post->_id}}</guid>  
            <description><![CDATA[ {{substr(strip_tags(@post->content),0,256)}} ]]></description>
        </item>
        </repeat>
    </channel>
    </rss>