filter_content

Description

Apply a lambda function to filter out content that meets specified criteria yet is not pinned to a location in a data feed.

list filter_content( array input , lambda definition )

Evaluates a lambda for every element in the list, and returns a new list with only the elements that evaluated to true as well as any items that were saved as a pinned item in Recommendation Manager. This is especially useful for filtering out content items based on their properties, such as URL or tags, or filtering out duplicate content items.

If you want to filter objects other than a data feed, such as arrays, use filter() instead of filter_content(). You should also use filter() if you want to filter data feed content without regard to whether items are pinned.

Examples

Filtering only for pieces of content that are tagged furniture:

{content = filter_content(content, lambda x: contains(x.tags, 'furniture'))}

Filter out pieces of content that are tagged “explicit-content”:

{content = filter_content(content, lambda x: !contains(x.tags, 'explicit-content'))}

Removing duplicate content based on title:

{duplicates = []}
{content = filter_content(content, lambda x: contains(duplicates, x.title)?false:duplicates = duplicates + [x.title] || true)}

Cancel if There’s Not Enough Content to Show a User

Use Case: Cancel if there’s not enough content to show a user

{content = filter_content(content, lambda c: c.vars.sailthru_vertical && c.vars.sailthru_topic == 
profile.vars.favorite_topic)}

{cancel(length(content) < 1, "No content in the user's favorite topic!")}

Explanation: This script is using the filter_content function to only include any content that has a topic variable that equals a "favorite_topic" variable on the user's profile. It then checks how many items are left using the length() function. If there's less than 1 (i.e. no items), then the cancel() function stops the email from going out to that specific user.

Top