[SalesForce] AMPSCript HTML assign variable

Do you know If It is possible to assign a variable that has dynamic content on it?. Similar to:

VAR @HTML
SET @HTML BEGIN
Hi, Miguel your email is: %%=TreatAsContent(@email)=%%. 
Thanks for using our services Date %%Date%%.
SET @HTML END

And then access the variable @HTML that contains custom html and other variables and play with it?

Obviously SET @HTML BEGIN and SET @HTML END won´t work but I just wanted to know If there is any workaround for this.

Best Answer

It might be helpful to read over the official AMPScript Syntax Guide.

Here's an example:

%%[

var @email, @servicesDate
set @email = AttributeValue("email")
set @firstName = AttributeValue("firstName ")
set @servicesDate = AttributeValue("servicesDate")

]%%

Hi, %%=v(@firstName)=%%

Your email is: %%=v(@email)=%%. 

Thanks for using our services Date %%=format(@servicesDate,"MM/dd/yyyy")=%%.

Use %%[ and ]%% to delimit your AMPScript blocks, then reference variables with the %%=v(@varName)=%% syntax outside of the AMPScript block.

EDIT: You can always add HTML content to an AMPScript variable using the content area/block functions:

%%[

var @email, @servicesDate
set @email = "<h1>whee!</h1>"
/* OR */
set @email = ContentAreaByName("my contents\PATH\TO\YOUR\CONTENT")
set @firstName = AttributeValue("firstName ")
set @servicesDate = AttributeValue("servicesDate")

]%%

EDIT: There are some more complete examples here: