dedupe

Description

Remove duplicate items from an array of content recommendations, so that the same product or article is not displayed more than once.

Copy
array dedupe( array input [, string field] )

Based on the specified field–the name of any content attribute supported by the Content API such as a key (e.g. url) or var–deduplicate the array of content items, returning a new content array in which the value for each field exists only once. The default field (when the field parameter is not specified) is url — the URL of the content items. Note: If you want to deduplicate a content feed while maintaining the locations of content items that are pinned using Recommendations, use filter_content() instead.

Examples

  • Deduplicate the content array based on matches of the url field:
    {content = dedupe(content)} or {content = dedupe(content, "url")}
    Either of the above would transform the following content array to remove duplicate URLs:
    content Before
    {
        "url" : "http://example.com/1",
        <additional fields>
    },
    {
        "url" : "http://example.com/2",
        <additional fields>
    },
    {
        "url" : "http://example.com/2",
        <additional fields>
    },
    {
        "url" : "http://example.com/3",
        <additional fields>
    }
    content After
    {
        "url" : "http://example.com/1",
        <additional fields>
    },
    {
        "url" : "http://example.com/2",
        <additional fields>
    },
    {
        "url" : "http://example.com/3",
        <additional fields>
    }
  • Deduplicate the content array based on matches of the sku field:
    {content = dedupe(content, "sku")}
  • Deduplicate the content array based on matches of the title field:
    {content = dedupe(content, "title")}
  • Deduplicate the content array based on matches of a content var named item_id:
    {content = dedupe(content, "vars.item_id")}
  • Deduplicate the content array based on matches of a content var named item.id:
    {content = dedupe(content, "vars.item.id")}