How to Code an Automated Email with Multiple Rss Feeds

In this example we're going to focus on the FeedOtter code that allows you to incorporate multiple data feeds into your FeedOtter automated emails. Please note, this post is all about the code! If you're looking for a simple setup guide please read our walkthrough post.

We start with the standard FeedOtter post loop that loops through your RSS feed and displaying fields. For more information on the fields and loop basics see our post on creating custom rss email templates.

{% for post in feedotter.posts | slice(0,2) %}
	<div>
	{{post.post_url}}
	{{post.post_title}}
	{{post.post_author}}
	{{post.post_date}}
	{{post.post_excerpt_text | truncate(200,true,"...")}}
	{{post.post_source_url}}
	{{post.post_source}}
	{{post.post_url}}
	{{post.image_url}}
	</div>
 {% endfor %}

Building an email to use multiple feeds is similar with one exception: we add a number to the end of the post feed to specify which feed to reference. In the code snippet below I have copied the standard loop and added "post2" and "posts3" to each sections for loop.

{% for post in feedotter.posts | slice(0,2) %}
	<div>
	{{post.post_url}}
	{{post.post_title}}
	{{post.post_author}}
	{{post.post_date}}
	{{post.post_excerpt_text | truncate(200,true,"...")}}
	{{post.post_source_url}}
	{{post.post_source}}
	{{post.post_url}}
	{{post.image_url}}
	</div>
 {% endfor %}
 
 {% for post in feedotter.posts2 | slice(0,2) %}
	<div>
	{{post.post_url}}
	{{post.post_title}}
	{{post.post_author}}
	{{post.post_date}}
	{{post.post_excerpt_text | truncate(200,true,"...")}}
	{{post.post_source_url}}
	{{post.post_source}}
	{{post.post_url}}
	{{post.image_url}}
	</div>
 {% endfor %}
 
 {% for post in feedotter.posts3 | slice(0,2) %}
	<div>
	{{post.post_url}}
	{{post.post_title}}
	{{post.post_author}}
	{{post.post_date}}
	{{post.post_excerpt_text | truncate(200,true,"...")}}
	{{post.post_source_url}}
	{{post.post_source}}
	{{post.post_url}}
	{{post.image_url}}
	</div>
 {% endfor %}

 

The loop code and numbering can be seen beneath each feed URL in the FeedOtter interface:

Feed Loop Code Example

Slicing

Slicing allows us to specify how many posts from each feed we want to display.  In the code example below I have added " | slice(0,2)" to the FOR loop.  This notation means start at post 0 and return 2 posts.

{% for post in feedotter.posts | slice(0,2) %}
	<div>
	{{post.post_url}}
	{{post.post_title}}
	{{post.post_author}}
	{{post.post_date}}
	{{post.post_excerpt_text | truncate(200,true,"...")}}
	{{post.post_source_url}}
	{{post.post_source}}
	{{post.post_url}}
	{{post.image_url}}
	</div>
 {% endfor %}
 
 {% for post in feedotter.posts2 | slice(0,2) %}
	<div>
	{{post.post_url}}
	{{post.post_title}}
	{{post.post_author}}
	{{post.post_date}}
	{{post.post_excerpt_text | truncate(200,true,"...")}}
	{{post.post_source_url}}
	{{post.post_source}}
	{{post.post_url}}
	{{post.image_url}}
	</div>
 {% endfor %}
 
 {% for post in feedotter.posts3 | slice(0,2) %}
	<div>
	{{post.post_url}}
	{{post.post_title}}
	{{post.post_author}}
	{{post.post_date}}
	{{post.post_excerpt_text | truncate(200,true,"...")}}
	{{post.post_source_url}}
	{{post.post_source}}
	{{post.post_url}}
	{{post.image_url}}
	</div>
 {% endfor %}

This feature can be used to gain precise control over what posts are displayed.  This can be useful if you are injecting ads or other more static content into your emails.

At this point we've got the basic code structure for a multiple feed html email but there are a couple great tricks to make your multiple feed email even better.

Add "IF" statements to hide feed content that is not new

I'm going to wrap an if statement around the first post loop.

{% if feedotter.posts | length >0 %}
	{% for post in feedotter.posts | slice(0,2) %}
		<div>
		{{post.post_url}}
		{{post.post_title}}
		{{post.post_author}}
		{{post.post_date}}
		{{post.post_excerpt_text | truncate(200,true,"...")}}
		{{post.post_source_url}}
		{{post.post_source}}
		{{post.post_url}}
		{{post.image_url}}
		</div>
	 {% endfor %}
 {% endif %}
 
 {% for post in feedotter.posts2 | slice(0,2) %}
	<div>
	{{post.post_url}}

This says if there is new content in my first feed display it, otherwise hide content from the first feed.

This is great if you're building a big newsletter that has multiple sections.  You can display only the sections that have new content since your last send.

Always show content from a feed regardless of published date

By default FeedOtter only makes new content since your last send available in the posts loops.  In certain cases you may want to display less timely content such as eBooks, Whitepapers, Product Tutorials, or events.  In this case you may wish to modify the posts loop a bit further so that the first x posts from a feed always show up.

 {% for post in feedotter.allPosts2 | slice(0,2) %}
	<div>
	{{post.post_url}}
	{{post.post_title}}
	{{post.post_author}}
	{{post.post_date}}
	{{post.post_excerpt_text | truncate(200,true,"...")}}
	{{post.post_source_url}}
	{{post.post_source}}
	{{post.post_url}}
	{{post.image_url}}
	</div>
 {% endfor %}

By using "allPosts" instead of "posts" in the for loop we can grab the first 2 posts from a feed regardless of age.  The example loop above will display the first 2 items in feed 2... Always.

Wrapping it up

The multiple rss feed feature is available on FeedOtter's Plus and Advanced plans. There are example multiple feed emails in the FeedOtter templates library as well to serve as a starting point for exploring this exciting feature.

FeedOtter Can Help You Automate Blog and RSS Email

Promote your content and increase revenue from website traffic.
REQUEST A DEMO