Skip to main content

Using RSS Feeds

Using RSS Feeds

RSS feeds are declared using CircleScript at the top of the content that will pull from them. A feed can:

The simplest use case is to pull from a single anonymous feed with no duplicate suppression, e.g.

$feed (http://www.news.com/feeds/news)

RSS feeds

RSS feeds are declared with the $feed directive. This directive fetches articles from the given <URL> and makes them available to be loaded into the content.

$feed [<feed-name>] [(unique:<scope>; mapper:<mapperName>; filter:<filter-spec>,... ; sort:<sort-spec>,...)] (<URL>)

Only <URL> is required. All other parameters are optional.

RSS articles

Once a feed has been declared, RSS articles are loaded using the $article or the $each-article directives.

$article [<feed-name>] [(peek)]

This directive loads the contents of the next available article into predefined variable definitions. If no articles are available, the predefined variables are cleared.

<feed-name> and (peek) are optional.

  • When the <feed-name> parameter is omitted, the article is loaded from the first feed that has not yet been exhausted.

  • The (peek) option loads the article, but still leaves it in the feed.

    The (peek) option is useful when you want to use the lead story's title in your subject line but read the article inside an $each-article loop.

    By invoking $article (peek) at the top of your content, you make that article's title available for the subject line, but it will also be available in your first $each-article block.

    Note: if (peek) is specified and the feed is empty, then content processing will fail.

$each-article [<feed-name>] [1..<max>]

This directive invokes the remainder of the block (or content file) up to <max> times, or until there are no more articles available. The effect is as if the $article directive were added to the top of the repeating block.

<feed-name> is optional. [1..<max>] is required, and the square brackets [] are a part of the syntax.

  • When the <feed-name> parameter is omited, the article is loaded from the first feed that has not yet been exhausted.

Example: pull from named feeds (no suppression of duplicates).

$feed news (http://www.news.com/feeds/news)
$feed entertainment (http://www.news.com/feeds/entertainment)
$article news
$each-article entartainment [1..2]
$article

In this example:

  • $article news pulls the first article from the "news" feed.

  • $each-article entartainment [1..2] pulls the first two articles from the "entertainment" feed.

  • $article pulls the second article from "news", if available, or the third article from "entertainment" otherwise.

Getting a feed's size

You can get the size of a feed (or feeds) using the $feed_size(name) script function.

Example: Get the count of all articles still available across all feeds.

[$feed_size()]

Example: Get the count of all articles in feeds named "feed1".

[$feed_size(feed1)]

$feed_size() is typically used with $each-article to skip section if there aren't enough articles.

Example:

[$$?[$greater_than([$feed_size(feed1)], 2):[$$$each-article feed1 [1..3]
...[$article.title]...
$$]$$]

The $greater_than(...) function, and others like it, always evaluates as blank when the condition is false, i.e. when [$feed_size(feed1)] isn't greater than 2).

Powered by Zendesk