0

I'm looking for a way to inject HTML into a specific location in an email. I'm thinking something like a javascript DOM. Essentially We have coupons that use a specific set of variables, lets use these for examples

set @discount = "25% off"
set @product = "Sheep"
set @legal = "cannot be used in Antarctica or surrounding areas"

Due to templates and other integration issues, all of our coupons use the same variables, so when we have multiple coupons we have to redefine the variables before each coupon. This isn't a problem until we get to the footer, where we also include the legal disclaimers, and other information from the coupons. In order to do this currently, we currently redefine all the variables again in the footer. I'm looking for a way to define the variables once, and then include the code for both the coupon and the footer, and be able to tell the footer to appear in the bottom of the email, say inside a <table id="footer"> element.

This seems possible to me, since it's not being executed after the email has loaded, but I haven't found the functionality in the documentation yet. Anyone have any ideas how to do this?

Side note: I am trying to get the templates to a point where we use separate variables for each instance of a coupon, say @discount2, @product2, and @legal2, or something, but it's a slow process so I'm looking for other solutions.

2
  • So you want an array of coupon codes to display in various places in the email? Commented Jan 16, 2017 at 17:48
  • Not exactly. I can't currently use multiple variables for different coupons. In other words, each coupon and disclaimer MUST use the same variables. I'm looking for a way to simplify the code by defining a coupon/disclaimer pair in one place and displaying the coupon at the current location and the disclaimer using the same values for the variables at the bottom. Commented Jan 16, 2017 at 19:31

1 Answer 1

0

The ContentAreaByName Function could be used here:

If you create a ContentArea and inside this block you store Ampscript you would have the ability to write a IF/ELSE STATEMENT which would run based if these 3 variables are not empty.

Example:

Go to My Content/Folder and name the block Dynamic_Coupon_Information then pick HTML from here you can utilize this code:

%%[IF NOT EMPTY(@discount2) AND  NOT EMPTY(@product2) AND NOT EMPTY(@legal2) THEN
        SET @discount = "25% off"
        SET @product = "Sheep "
        SET @legal = "cannot be used in Antarctica or surrounding areas."
        SET @CONSOLIDATED_TEXT = TreatAsContent("@discount @product @legal")

        ELSE THEN

        SET @discount = ""
        SET @product = ""
        SET @legal = "Based on availability due to limited supply."
        SET @CONSOLIDATED_TEXT = TreatAsContent("@legal")

ENDIF]%%

      %%=v(@CONSOLIDATED_TEXT)=%%

Put this function in your footer thus it executes the IF/ElSE statement above stored in the block.

%%=ContentAreaByName('my contents\folder\Dynamic_Coupon_Information')=%%
3
  • Please do not use link shorteners. If you would like to link to some content, do so directly.
    – Adrian Larson
    Commented Sep 15, 2017 at 21:02
  • Sorry!! noted for the future Thanks -James Commented Sep 15, 2017 at 21:17
  • Thanks for the answer @DatasetJames, but this won't actually accomplish what I'm looking for. I see what you're driving at, and it would accomplish the end result, but I'm not sure that it will simplify the situation the way I'm looking for. Essentially what I think I'm looking for is the ability to use variables in one section and be able to use those values again without redefining them. Without some form of DOM, the only way to really accomplish this is through using a global variable, which I've started adjusting to. Commented Sep 18, 2017 at 11:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .