Advanced Dynamic Content Cheatsheet

This section details the variables used for advanced dynamic messages.

Users 

VariableTypeDescription
${user.id}StringUser ID
${user.userName}StringName
${user.userNameOrAnonLocation}StringName or “user from City, State”
${user.accountType}StringAccount type
${user.emailAddress}StringEmail address

User Location 

VariableTypeDescription
${user.location.postalCode}StringZIP code
${user.location.city}StringCity
${user.location.metro}StringMetro area
${user.location.metroCode}IntegerMetro code
${user.location.region}StringState/region
${user.location.stateProvinceCode}StringState/region code (shorthand)
${user.location.country}StringCountry
${user.location.countryCode}StringCountry code (shorthand)
${user.location.organization}StringOrganization
${user.location.industry}StringIndustry
${user.location.naicsCode}IntegerNorth American Industry Classification System code

User Custom 

VariableDescription
${user.attributes._________}Custom Attribute (Use dropdown in editor for specific ID)

Items 

Things that count as items:

  • Products
  • Articles
  • Blogs
  • Catalog Objects
  • Categories

Basic 

Must have intended item query selected in message settings

VariableTypeDescription
${item}ObjectItem object
${items}ArrayArray of item objects
${items[0]}...${items[9]}ObjectItem in array
${page.item}ObjectCurrent page item object
${page.category}ObjectCurrent page category or category of current page item
${item.name}StringItem name
${item.id}String or IntegerItem ID
${item.url}StringItem URL
${item.imageUrl}StringImage URL
${item.description}StringItem description
#field(${item.rating}, '0')IntegerAverage rating
#field(${item.numRatings}, '0')IntegerNumber of ratings
${item.categories}ArrayCategories objects
${item.dimensions}ArrayAll related Catalog Objects
Custom VariablesDescription
${item.attributes.xxxxx.value}Value of the attribute named “xxxxx” on the item

Products Only 

VariableTypeDescription
${item.price}IntegerPrice. NOTE: Unformatted. For more information, see Utilities.
${item.priceDescription}StringPrice description
${item.listPrice}FloatList price. NOTE: Unformatted. For more information, see Utilities.
${item.inventoryCount}IntegerInventory count
${item.brands}ArrayBrand tag objects
${item.classes}ArrayClass tag objects
${item.styles}ArrayStyle tag objects
${item.genders}ArrayGender tag objects

Build Item Query in Message (Advanced) 

Query Type: Global/User Interchangeable 

VariableDescription
${tools.global...}Query Global Statistics
${tools.user...}Query User Statistics
${tools.global.products...}Query Products
${tools.global.articles...}Query Articles
${tools.global.blogs...}Query Blogs
${tools.global.categories...}Query Categories
${tools.global.brands...}Query Brands
${tools.global.styles...}Query Styles
${tools.global.authors...}Query Authors
${tools.global.keywords...}Query Keywords

Query: Default Array Length Min 1 Max 5 

VariableTypeDescription
${tools.global.products.viewCount()}ArrayTop viewed products by count
${tools.global.products.viewTime()}ArrayTop viewed products by time
${tools.global.products.cartCount()}ArrayProducts most added to cart by count
${tools.global.products.cartValue()}ArrayProducts most added to cart by currency
${tools.global.products.purchaseCount()}ArrayTop purchased products by count

Ensure that you either iterate over every product in an array

Global Only 

VariableTypeDescription
${tools.global.products.publishedDate()}ArrayMost recently published product

User Only 

VariableTypeDescription
${tools.user.products.viewed()}ArrayMost Recently Viewed
${tools.user.orders.currentItems()}ArrayProducts in cart. Note: Personalization doesn’t currently track cart removals.
${tools.user.orders.currentValue()}FloatTotal cart value. Note: Unformatted, see utilities.
${tools.user.get('Engagement', 'none')}User’s Engagement Score

Item Options 

You can further refine results from query functions by passing them a set of item options, as shown in the following example.

1$tools.user.products.viewCount(${itemOptions...})

You can specify item options by calling multiple functions on the itemOptions object, as shown in the following example.

1${itemOptions.optionOne().optionTwo().optionThree()}

Sizes 

By default, a message containing advanced dynamic queries renders only if there’s at least 1 result.

To increase the minimum number of items returned, use ${itemOptions.minItems(<Integer>)}.

To increase the maximum number of items returned, use ${itemOptions.maxItems(<Integer>)}.

You can’t increase the maximum number of items returned beyond 10.

Note

Filters 

You can further filter query results using the following filters.

FilterDescription
${itemOptions.withCategory(<CategoryID>)}Filter results by the category the visitor is currently viewing.
${itemOptions.withBrand(<BrandID>)}Filter results to contain only items with a specific brand.
${itemOptions.withBrandAnyOf([<BrandID1>,<BrandID2>,...])}Filter results to contain items from any of the specified brands.
${itemOptions.withGender(<GenderID>)}Filter results by gender.
${itemOptions.withGenderAnyOf([<GenderID1>,<GenderID2>,...])}Filter results by any of the specified gender IDs.
${itemOptions.withKeyword(<KeywordID)}Filter results by a specified keyword.
${itemOptions.withKeywordAnyOf([<KeywordID1>,<KeywordID2>,...])}Filter results by any of the specified keywords.
${itemOptions.withAuthor(<AuthorID)}Filter results by AuthorID.
${itemOptions.withAuthorAnyOf([<AuthorID1>,<AuthorID2>,...)}Filter results by any of the specified authors.
${itemOptions.withContentClass(<ContentClassID>)}Filter results by ContentClassID.
${itemOptions.withContentClassAnyOf([<ContentClassID1>,<ContentClassID2>,...])}Filter results by any of the specified content classes.
${itemOptions.withStyle(<StyleID>)}Filter results by style.
${itemOptions.withStyleAnyOf([<StyleID1>,<StyleID2>,...])}Filter results by any of the specified styles.
${itemOptions.withItemClass(<ItemClassID>)}Filter results by item class.
${itemOptions.withItemClassAnyOf([<ItemClassID1>,<ItemClassID2>,...])}Filter results by any of the specified item classes.
${itemOptions.whereCreated(<TimeObject>)}Filter results by date or time range of creation. To know more about the available TimeObject functions, see Lookback Period.
${itemOptions.wherePublished(<TimeObject>)}Filter results by published or time range. To know more about the available TimeObject functions, see Lookback Period.

Lookback Period 

To specify a lookback period apart from the default lookback period of the past week, use:

1${itemOptions.time(<TimeObject>)}

The following functions are provided by the $time singleton object:

FunctionDescription
todayToday
thisWeekCurrent calendar week (with Monday as first day of week)
thisMonthCurrent calendar month
since(date)Since the specified date; date format is “mm/dd/yyyy” (for example “07/07/2017”)
lastNDays(n)Last n days, including today; lastNDays(1) would mean today and yesterday
allTimeDon’t define a specific date range

Conditional Options 

The itemOptions object provides several conditional options or methods that you can call to filter or manipulate its properties based on certain conditions.

Conditional OptionDescription
${itemOptions.whereName()...}Filter data based on item name.
${itemOptions.whereDescription()...}Filter data based on item description.
${itemOptions.whereUrl()...}Filter data based on item URL.
${itemOptions.whereImageUrl()...}Filter data based on an item’s image URL.
${itemOptions.wherePriceDescription()...}Filter data based on item price description.

Conditionals 

You can use conditionals with conditional options to further refine the data being filtered.

1${itemOptions.whereName().exists()}

The following conditionals are available for use.

ConditionalDescription
exists()Checks whether the property being filtered exists.
doesNotExist()Checks whether the property being filtered doesn’t exist.
contains(<String>)Checks whether the property being filtered contains the specified string.
doesNotContain(<String>)Checks whether the property being filtered doesn’t contain the specified string.

Sorting 

To sort the results for display, use the displaySort function.

1${itemOptions.displaySort(<SortOptions>)}

To sort results for display in the descending order, use the descending function.

1${itemOptions.descending()}

The displaySort function provides the following sort options.

Sort OptionDescription
${productSort.name()}Sort products by name.
${productSort.price()}Sort products by price.
${articleSort.name()}Sort articles by name.
${articleSort.publishedDate()}Sort articles by published date.
${blogSort.name()}Sort blogs by name.
${blogSort.publishedDate()}Sort blogs by published date.

To sort results for display in the descending order, use the descending function.

1${itemOptions.descending()}

Inclusions 

To include items a visitor is currently viewing in query results, use:

1${itemOptions.includeItemsBeingViewed()}

To include items in a visitor’s cart in query results, use:

1${itemOptions.includeItemsInCart()}

Exclusions 

To exclude items a visitor has already purchased from query results, use:

1${itemOptions.excludePurchasedItems()}

To exclude items a visitor has already viewed from query results, use:

1${itemOptions.excludeViewedItems()}

Utilities 

If/Else Statements 

1<!-- #if ($user.attributes.firstName) -->
2<div>Hello $user.attributes.firstName</div>
3<!-- #else -->
4<div>You don't have a first name at all</div>
5<!-- #end -->

Set Variables 

1#set (${variableName} = $...)

Loops 

1#foreach (${variableName} in <Array>)
2...
3#end

Format Price 

There are two ways to format prices.

  • By passing the price as a floating-point number to the formatPrice method. The formatPrice method formats the given number as a price, with the default dataset currency symbol and appropriate decimal formatting, and returns the formatted string.

    1$tools.formatPrice(<Float>)

    In Open Time Email Templates, only the $currencyTools.formatPrice(<Float>) method is available. This method is used instead of is used instead of the $tools.formatPrice(<Float>) and $tools.formatNumber(<Float>, <Int Number of Fractional Digits>) methods.

    Important

  • By passing the price as a floating-point number and a fixed number of digits after the decimal point to the formatNumber method.

    1$tools.formatNumber(<Float>, <Int Number of Fractional Digits>)

Field 

The #field utility enables you to provide a fallback value for an attribute.

1<div>#field($item.attributes.testString, "Item does not have a testString attribute")</div>