0

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]%%

TIA

2 Answers 2

1

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"
else
  set @x = "whee"
endif

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

]%%
%%=v(@layout)=%%

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

<table>
<tr>
<td>
%%=iif(empty(@x),"is empty","is not empty")=%%
</td>
</tr>
</table>

Using outputline() is also an option:

%%[

var @layout, @x

set @x = "whatever"

outputline(concat("<table><tr><td>"))
outputline(concat("the value is: ",@x))
outputline(concat("</td></tr></table>"))

]%%
3
  • 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
0

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")
%%[else]%%
@subheader = ContentAreaByName("my content...B")
%%[endif]%%

< body >
%%=v(@subheader)=%%
< /body >

You must log in to answer this question.

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