Important: This article assumes an understanding of conditional statements, the display conditions control, and product recommendation merge tags. |
Some email types in Cortex can have inconsistent numbers of product recommendations. When working with these emails we want to make sure that no users receive a layout that shows empty or broken product recommendation blocks.
Luckily, we can use the template builder's Display Conditions Control to avoid showing any blank recommendations to our shoppers. This article will cover the display conditions used in the "New Arrivals Conditional Display" Starter Template.
The goal
Our goal is to build a template that will not display any blank recommendations to the reader. It will display a minimum of one product recommendation, and a maximum of 7 product recommendations. The number of recommendations displayed will vary, dependent on the number of available product recommendations.
The example layout below works best with "only (stage rule)" recommendation schemes such as "only New Arrivals" and "only Cart Abandoned Items".
The approach
New Arrivals will not send an email with no product recommendations – product recommendation 1 will always exist. This means we can ignore it when setting our display conditions.
We will use conditional statements to create display conditions for counts between 2 and 7 recommendations. To determine the number of available recommendations we will check the value of the {{rs_rnX}} merge tags, to see if there is a product available for recommendation "X".
The layout
For simplicity's sake, we will reduce the number of display options in our template. We will display either 1, 3, 4, or 7 recommendations. To achieve this we will use one row of two recommendations, and two rows of three recommendations, laid out as shown:
Building display conditions
Under what conditions should each row of recommendations be shown?
Each row should be shown if...
- All recommendations are available
- The included recommendations are not repeated in another row
Let's look at the first row, with recommendations 2 and 3. If we have 3 recommendations available we should show this row. However, if we have 4 or more recommendations, we should show a row of 3 instead. So we want our formula to look like this: "If (recommendation 3 exists) and (recommendation 4 does not exist". Because we cannot use parentheses in our conditionals, we will use two nested if statements: {% if recommendation 3 exists %}{% if recommendation 4 does not exist %}. Combining two if statements this way is the same as using an AND condition.
To decide if a recommendation exists, we will make sure that the recommended product name is not null, and is not an empty set of characters ('').
logic | example |
recommendation X exists | {% if rs_rnX != null and rs_rnX != '' %} |
recommendation X does not exist | {% if rs_rnX == null or rs_rnX == '' %} |
The display conditions used in the example template are shown below.
Row 1, recommendations 2 & 3:
This logic controls the banner "More You're Sure To Love". It would be weird to show this banner without additional product recs, so we will only show it if we are going to show at least 3 product recommendations.
Only use this format if no other rows share these merge tags. You can see in the example above that Recommendations 2 & 3 appear in both rows 1 and 2. To ensure that rows 1 and 2 are not shown together, use the next example.
Row 1, recommendations 2 & 3:
This logic controls the first row of recs, that contains product recs 2 and 3. We only want to show this row of product recs if exactly 3 recs exist, no more and no less. The first if statement checks to see if product rec 3 exists. The second if statement makes sure product rec 4 does not exists. By placing the two if statements back to back they function as a larger if, "if (statement 1) and (statement2)"
Row 2, recommendations 2-4:
Row 3, recommendations 5-7:
This logic controls the last two rows of recs. If 4 recs exist we want to make sure we show all 4 product recs. We know that hiding the duplicate recs in row 2 and 3 is handled by the previous display condition. These display conditions only need to check if recs exist up to rec 4 or rec 7.
Video example:
This video shows how the display conditions were built for the example template: https://www.screencast.com/t/KpMFapTDV
Please note: there is one missing % in the video
Comments
0 comments
Please sign in to leave a comment.