Is there any way to scan the body of an email with AMPscript, identify all legal notes superscripts and then have the corresponding legal notes displayed in order in the footer area?
-
1Does it have to be an Ampscript solution?– 0xsegfaultJun 1, 2017 at 4:53
-
Could you provide a sample of the content we would be parsing for content that requires a footnote, please?– MaccaJun 2, 2017 at 3:54
-
something like this Andrew:– SnowalkerJun 5, 2017 at 13:00
-
Some content <sup>1</sup>, some more content <sup>5</sup> and some even more content<sup>3</sup>.– SnowalkerJun 5, 2017 at 13:10
-
I need the footnotes in the footer section to be in order, in this case 1, 3, 5– SnowalkerJun 5, 2017 at 13:10
2 Answers
It depends on where your email HTML content lives. If it's in a Content Area, you could do something like this:
%%[/* Modify to view AMPScript <div style="display:none"> */
var @content, @showfootnote1, @showfootnote2, @showfootnote3
set @content = ContentAreaByName("my contents\testEmailContent")
set @showfootnote1 = iif(indexOf(@content,"<sup>1</sup>") > 0,1,0)
set @showfootnote2 = iif(indexOf(@content,"<sup>2</sup>") > 0,1,0)
set @showfootnote3 = iif(indexOf(@content,"<sup>3</sup>") > 0,1,0)
/*</div>*/
]%%
%%[ if @showfootnote1 == 1 then ]%%
<!-- footnote 1 content here -->
%%[ endif ]%%
%%[ if @showfootnote2 == 1 then ]%%
<!-- footnote 2 content here -->
%%[ endif ]%%
%%[ if @showfootnote3 == 1 then ]%%
<!-- footnote 3 content here -->
%%[ endif ]%%
-
Thanks Adam but we don't use content areas for this email in particular. Is there any way to make this work? Jun 5, 2017 at 20:11
-
Not unless you have the content stored somewhere besides the email definition. Without that, there's no opportunity to search through the content before the send occurs. Jun 6, 2017 at 2:12
I have used something similar, all based on conditionals, that has worked gracefully and handles many different situations.
For instance, let's say an email COULD include a reference to products A, B, and/or C, and each has a unique footnote, but not every email could have all of those items. Like one customer has A, B and C, but another might just have B, a third might have A and C, and another might have B and C... I use variables, if/then, and counting (add function) to determine what footnotes should display in the footer.
AMPScript Code Block (I recommend putting this at the top of your email):
(Assumes field/attribute names of HAS_PROD_A, HAS_PROD_B, and HAS_PROD_C in your list/data extension, all with Y/N values)
%%[
var @supTtl, @supA, @supB, @supC
SET @supTtl = 1 /*starting footnote number*/
If HAS_PROD_A == "Y" THEN
SET @supA = @supTtl
SET @supTtl = Add(@supTtl, 1)
ENDIF
If HAS_PROD_B == "Y" THEN
SET @supB = @supTtl
SET @supTtl = Add(@supTtl, 1)
ENDIF
If HAS_PROD_C == "Y" THEN
SET @supC = @supTtl
SET @supTtl = Add(@supTtl, 1)
ENDIF
]%%
Explanation:
The @supTtl variable acts as a counter in the AMPScript. It starts out with a value of 1, and iterates to the next value only if the conditional test for each product is true. The @supA, @supB, @supC variables will hold the current value of @supTtl at the time they are set. They won't change if @supTtl is changed to a plus one for the next product. (i.e. if all three products are present, A will stay 1, B will stay 2, and C will be 3).
In the HTML:
<!--%%[IF HAS_PROD_A == "Y" THEN]%%-->
<tr>
<td>
Product A description<sup>%%=v(@supA)=%%</sup>
</td>
</tr>
<!--%%[ENDIF]%%-->
<!--%%[IF HAS_PROD_B == "Y" THEN]%%-->
<tr>
<td>
Product B description<sup>%%=v(@supB)=%%</sup>
</td>
</tr>
<!--%%[ENDIF]%%-->
<!--%%[IF HAS_PROD_C == "Y" THEN]%%-->
<tr>
<td>
Product C description<sup>%%=v(@supC)=%%</sup>
</td>
</tr>
<!--%%[ENDIF]%%-->
Footnote section would work similarly:
<!--%%[IF HAS_PROD_A == "Y" THEN]%%-->
<tr>
<td>
<sup>%%=v(@supA)=%%</sup>Product A footnote information
</td>
</tr>
<!--%%[ENDIF]%%-->
<!--%%[IF HAS_PROD_B == "Y" THEN]%%-->
<tr>
<td>
<sup>%%=v(@supB)=%%</sup>Product B footnote information
</td>
</tr>
<!--%%[ENDIF]%%-->
<!--%%[IF HAS_PROD_C == "Y" THEN]%%-->
<tr>
<td>
<sup>%%=v(@supC)=%%</sup>Product C footnote information
</td>
</tr>
<!--%%[ENDIF]%%-->
So, the effect of the AMP Script and the HTML working together would basically be that only those products on each customer record would be displayed in the email, and the footnote numbers will retain their order even if one is skipped, or only one is displayed.
This code WILL cross into content areas if necessary - just make sure the AMPScript is located before any calls to any footnotes in the email. It also works well in HTML Paste emails. Been using it for some time now.
Incidentally, the comment tags around the AMPScript will not affect how it works, but it will keep your final HTML source code clean and free of alot of white space (just in case you were concerned).