This example shows an InsertIF expression to include dynamic content about local stores in an email using related data.
A company wants to include information about local stores opening in their regular newsletter. A promotion banner should be displayed only to customers who live near the store and only within 2 weeks before and 2 weeks after the newsletter run date.
See the Use Case video: Integrate Local Store Promotions in Your Regular Campaigns.
The related data parameters must exist in your Engage system if you want to use the code from this page. Please note that you must replace the parameters in the code with the ones that your system is using.
The related data set is called "stores" and uses the Linked User Attribute "user.CustomAttribute.city". It has two columns: OpeningDate, which represents the opening date of the local stores, and Image Url, which represents the URL of the image in the Content Store.
Example of the related data values in the related data set:
Here is a list of all parameters used in the example expression.
This parameter uses the store opening date from the related data set. It checks if the store opening is in the time range from two weeks before to two weeks after the newsletter run date. Only if these conditions are met will the banner be displayed in the email.
{ecm:between(user.RelatedAttribute.stores['OpeningDate'], ecm:addInterval(date['Today'], '-2W'), ecm:addInterval(date['Today'], '+2W'))}
CODE
This parameter looks at the Image Url value to select the image that should be displayed as a banner email.
{user.RelatedAttribute.stores['Image Url']}
CODE
Below is the full InsertIf expression.
<%InsertIf expression="${ecm:between(user.RelatedAttribute.stores['OpeningDate'], ecm:addInterval(date['Today'], '-2W'), ecm:addInterval(date['Today'], '+2W'))}" id="Adbanner"%>
<!-- Hero_Image start -->
<table cellspacing="0" cellpadding="0" align="center" border="0" width="660" bgcolor="#ffffff" style="width:660px;max-width:660px;background-color: #ffffff" class="w330px">
<tr>
<td align="center"><a href="#" target="_blank"><img src="<%${user.RelatedAttribute.stores['Image Url']}%>" width="660" height="356" class="w330px hauto" /></a>
</td>
</tr>
</table>
<!-- End Hero_Image -->
<%/InsertIf%>
XML