
Some users like to be informed of changes on your site through RSS syndication. Offering such a possibility is very simple in zena:
Let’s take the most common example: inform about new posts in a blog.
First you must create a template to display the list of recent posts in a format that feed readers can understand. You can choose between RSS and atom. In this example, we shall use RSS. The format is pretty straightforward: it’s an xml file with a list of dated entries.
Here is the zafu code:
<?xml version="1.0" encoding="utf-8"?>
<!-- generator="zena" -->
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel>
<title><![CDATA[<r:show attr='v_title'/>]]></title>
<description><![CDATA[<r:show attr='v_summary'/>]]></description>
<link do='[url]'/>
<lastBuildDate do='date' select='now' do='show' date='current_date' lang='en' format='%a, %d %b %Y %H:%M:%S %Z'/>
<pubDate do='date' select='now' do='show' date='current_date' lang='en' format='%a, %d %b %Y %H:%M:%S %Z'/>
<generator>http://zenadmin.org</generator>
<language do='[v_lang]'/>
<r:if test='id eq 1'><r:notes in='site' limit='20' order='log_at DESC' do='each'>
<item>
<title><![CDATA[<r:show attr='v_title'/>]]></title>
<link do='[url]'/>
<pubDate do='show' date='log_at' lang='en' format='%a, %d %b %Y %H:%M:%S %Z'/>
<description><![CDATA[<r:icon do='img' mode='pv'/><r:summary/>]]></description>
</item>
</r:notes>
<r:else><r:notes in='project' limit='20' order='log_at DESC' do='each'>
<item>
<title do='[v_title]'/>
<link do='[url]'/>
<pubDate do='show' date='log_at' lang='en' format='%a, %d %b %Y %H:%M:%S %Z'/>
<description><![CDATA[<r:icon do='img' mode='pv'/><r:summary/>]]></description>
</item>
</r:notes></r:else></r:if>
</channel>
</rss>
The code that actually fetches the latest posts is the ‘r:notes’ line:
<r:notes in='project' limit='20' order='log_at DESC'>
The rest is just to display information. The code is pretty simple and uses “show shortcuts” quite a lot. These shortcuts let you write do='[v_title]' instead of do='show' attr='v_title' to display the version’s title (attribute starts with v_). The other shortcut used is the “zazen shortcut” {v_summary} which displays the attribute but passes it to zazen (the textile parser).
The code above should be saved in a template with “rss” format and “Node” class scope. You can also import the rss template.
telling browsers about your feed
You must add a “link” tag inside the head of your project pages:
<link rel="alternate" type="application/rss+xml" do='project' set_title='[v_title]' name='rss_feed' format='rss' set_href='http://example.com[path]'/>
You should now see a sign in your browser indicating that there is an RSS feed available.
