Documentation

  1. Overview
  2. Creating Pages
    1. Editing Content
  3. Editing Templates
    1. Templating Language
    2. Assets
  4. Variable Types
    1. @variables
    2. $collections
    3. :partials
  5. RSS/Atom/JSON
  6. Download
    Stacey v2.3.0
  7. News & Updates
  8. Support
Stacey

RSS/Atom/JSON

Stacey doesn’t make too many assumptions about which format your templates are written in. It uses the extension of the template file to work out what type of content it should be serving. By default stacey will recognise and serve the correct content-types for .html, .json, .xml, .atom, .rss, .rdf & .txt files.

In fact, this is how the default RSS feed is built. The /content/feed directory is just a normal stacey page, the only difference is that it uses .atom rather than .html template files.

So, if you wanted to switch out Atom for the RSS2 format, your /templates/feed.atom template could be renamed to feed.rss and changed to look something like this:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>@name's @feed_name</title>
    <link>http://@base_url/@permalink/</link>
    <description>@description</description>

  :feed_loop

  </channel>
</rss>

Additionally, if clean urls are enabled, stacey creates file extension shortcuts for all the file types listed above. This means rather than having to point to http://yourdomain.com/feed/, you could shortcut this to http://yourdomain.com/feed.atom.

Cleaning JSON

Stacey will also automatically compress and strip any trailing commas from JSON templates. So, the following template:

get "/" do
{
  "pages": [
    foreach $children do
      { "title": "@title" },
    endforeach
  ]
}
end

will render as:

  {"pages":[{"title":"Projects"},{"title":"About"},{"title":"Contact"}]}