We are looking to store Ampscript in a DataExtension which relates to the dynamic build of a multi-language email campaign.

I have the following amscript which should pull in an IF statement stored in a data extenstion:

%%=TreatAsContentArea("VirtualCA_PRE", Lookup(@CAMPAIGN_AMP_SCRIPT,"AMPSCRIPT_PRE","ROW","CA"))=%%

The result of the Lookup is to pull in the following ampscript:

%%[IF (CELL_ID == "A000623139" OR CELL_ID == "A000623145" OR CELL_ID == "A000623142") THEN]%%

However when we preview the email I get the "An error occurred when attempting to parse Html Email Body content for HTML content." message.

Is it possible to store an IF statement like above and execute it directly from the DE?


  • What's after the IF statement in your email? An ENDIF? What happens when you use the Validate button in the toolbar? May 12, 2015 at 15:48
  • There is AMPSCRIPT_POST value that contains the ENDIF, and i think the issue may be that it doesn't see the two values as an IF statement "pair".
    – Paul Moody
    May 12, 2015 at 15:57
  • I think you are right, the AMPScript that is processed within TreatAsContent needs to be a valid by itself, it isn't processed in the context of the entire email. Concat() could be used to combine the value from the Lookup with the static piece that contains the ENDIF then that might work.
    – Mac
    May 12, 2015 at 19:24
  • Thanks Mac, yes, some early testing has indicated this is the case and that the content to TreatAsContent must be valid by itself. Concat certainly does work, I just need to work out how to wrap a block of HTML within an of Ampscript IF statement using concat. Will post the result when I find it.
    – Paul Moody
    May 13, 2015 at 7:51

1 Answer 1


Having done a fair bit more research and using the information listed above I can confirm that it is possible to store an IF statement within a DataExtension. However there are important things to consider:

  1. Both the open and the close of the IF statement must be processed at the same time when using the TreatAsContent function
  2. Your stored Ampscript within your DE should use single quotes rather than double quotes
  3. You can use the Concat function to combine Ampscript with HTML content

Here is an example:

/* Set the sample content - this could also come from a lookup          */
SET @CA_URL = "Image hyperlink goes here"
SET @CA_IMAGE = "Image path goes here"
SET @CA_ALT = "Alt text goes here"

/* For the purposes of this example assume the following IF statements  */
/* AMPSCRIPT_PRE  = "%%[IF (CELL_ID=='1234' OR CELL_ID=='4321') THEN]%% */
/* AMPSCRIPT_POST = "%%[ENDIF]%%"                                       */

/* Now concat your Pre and Post ampscript either side of some HTML      */
SET @CA = concat(lookup(@AMPSCRIPT_DE,"AMPSCRIPT_PRE","ROW","CA"),"<a href='%%=v(@CA_URL)=%%'><img src='%%=v(@CA_IMAGE)=%%' alt='%%=v(@CA_ALT)=%%' border='0' width='600'></a>",lookup(@CAMPAIGN_AMP_SCRIPT,"AMPSCRIPT_POST","ROW","CA"))

/* Now return using TreatAsContent */


You must log in to answer this question.

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