Slicing loops
Show posts from different parts or an RSS feed in different places in your email.
In many cases you may want to display a specific post or posts from your data source. We do this by applying a "slice" filter to the feedotter.posts element.
Slicing Syntax
Slicing is a Filter that is applied to a loop of FeedOtter posts.
[% for post in feedotter.posts | slice(0,1) %]
The "slice" filter accepts one or two parameters and works like this:
slice(3) // Start at the first post and loop 3 times. Displays post 1,2,3
slice(0,3) // Same as the first. Start at the first post and loop through 3 times. Displays post 1,2,3
slice(3,3) // Start looping at post 3 and loop 3 times. This will display post 3,4,5
More Examples
// Start looping at the first post(0) and stop after 1 post.
[% for post in feedotter.posts | slice(0,1) %]
[[post.post_title]]
[[post.post_url]]
[[post.post_description_text]]
[% endfor %]
// Skip post 1. Start looping with the second post(1). Stop after 4 posts
[% for post in feedotter.posts | slice(1,4) %]
[[post.post_title]]
[[post.post_url]]
[[post.post_description_text]]
[% endfor %]
Using the slice filter will override the Number of Posts UI dropdown.
Pay special attention to the | slice(0,1) part of the loop definition. The first number in the slice() function is the starting point so 0=first post in a data source. The second number is the length or number of posts to display or loop through.
Last updated