Creates a loop of numbers that can be applied to a data feed. Parameter 1 is the start index, parameter 2 is the end index, and a third (optional) parameter is the number of “steps” between.


Personalize and Display User’s Top Story in a Hero Section and Other Stories in a Sub-Section

Zephyr: In the Setup:

{interestContent = personalize({"algorithm":"interest","size":3,"content":content})}

In the Code:

Your top story for the day!
{foreach range(0,1,1) as i}
<a href={interestContent[i].title}>{interestContent[i].title}</a>
Other stories we think you'd enjoy:
{foreach range(1,2,1) as i}
<a href={interestContent[i].title}>{interestContent[i].title}</a><br/>

Output: Your top story for the day! From the Fashion Blog: The Most Comfortable Socks You’ll Ever Own Other stories we think you’d enjoy: Spider-Man: Threat or Menace? Stephen King’s New Book is a Real Scream!

Description: This script uses the personalze() function to find a user’s top three stories based on user interest, creating a local variable called “interestContent,” which contains each user’s top three stories, starting with the most interested. Next, it uses the range() function in conjunction with a foreach loop to start at the beginning of the list (index 0) and runs one time with a “step” of 1 (meaning how far to go, in this case, grab the first item). This item gets display in the “Hero” section. Next, a similar method is used to find the two remaining stories. This time, the range() function starts at the second item in the list (index 1), runs 2 times, again with a “step” of 1. This populates the secondary items sub-section.

Contact us