I'm trying to use the AMPScript to control the layout of the email and I will be using identical info to display in the email for various layouts.

Is there a way to set a variable with html code.

Set @layout1 = "< table >< tr >< td >%%[if @x == "" then]%%%%[else]%%%%[endif]%%< /td >< /tr >< /table >"

%%[if @y == "" than ]%% @layout1 %%[elseif @z == "" than]%%%%[endif]%%


2 Answers 2


There are several ways to go about this.

You might take a look at the AMPScript Function and Syntax help pages.

You can use the concat() function in an AMPScript block:


var @layout, @x

if @whatever == @something then
  set @x = "whoops"
  set @x = "whee"

set @layout = concat("<table><tr><td>",@x,"</td></tr></table>")


You can also embed it in the body of the email and use the iif() function:

%%=iif(empty(@x),"is empty","is not empty")=%%

Using outputline() is also an option:


var @layout, @x

set @x = "whatever"

outputline(concat("the value is: ",@x))

  • Thanks Adam, I looked into concat and I didn't know how to include double quotes without breaking it so I went with ContentAreaByName and it works.
    – Kyu
    Commented Jul 30, 2015 at 21:58
  • Please update your question with your solution, so we can all benefit. Commented Jul 31, 2015 at 0:05
  • 2
    You can use single quotes for the declaration of AMPscript value and use double quotes inside without breaking it. Eg - SET @y =CONCAT(@x,'<table style="text-align: center">') Commented Jul 31, 2015 at 2:49

Thanks guys. I decided to use ContentAreaByName() which allows me to make updates to the content without having to search the AMPScript code.

%%[if @x == "" then]%%
@subheader = ContentAreaByName("my content...A")
@subheader = ContentAreaByName("my content...B")

< body >
< /body >

You must log in to answer this question.

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