Print AMPscript Variable inside HTML as attributes

So I am using ExactTarget templates and content areas to build my emails. In my templates I have AMPscript variables defined in the < head > and that will determine how elements in my content areas will render. For Example:

Inside My Template

%%[
SET @Title_Color = "#1996e6"
]%%

Inside My Content Area

...
<td class="title_text" align="center" style="font-size:20px; color: %%=v(@Title_Color)=%%;">[MY TITLE]</td>
...

Keep in mind these content areas are built as FREE FORM content areas. This is important to note as the marketers need to be able to modify the content in the WYSIWYG and still have these AMPscript variables evaluate properly.

The problem I am running into is 2 fold. I am inside of an Enterpise 2.0 environment and in some business units the above code works fine, but in some business units when I save the content area and re-open it the the AMPscript is removed completely (along with the related CSS property) and I am left with this:

...
<td class="title_text" align="center" style="font-size:20px;">[MY TITLE]</td>
...

So as a workaround I built the entire style attribute as a AMPscript variable and inserted that into the < td >. Below is my code:

Inside My Content Area

%%[
SET @Title_Style = Concat('style="font-size:20px; color:',@Title_Color,';"')
]%%
...
<td class="title_text" align="center" %%=v(@Title_Style)=%%>[MY TITLE]</td>
...

This worked for half of my business units but completely broke in the other half. For the ones that broke ET changed my AMPscript appear like the following (notice the extra quotes (“) and equal sign (=) around the AMPscript in the HTML):

%%[
SET @Title_Style = Concat('style="font-size:20px; color:',@Title_Color,';"')
]%%
...
<td class="title_text" align="center" %%="v(@Title_Style)=%%"="">[MY TITLE]</td>
...

MY QUESTION:

Does anyone have any idea how to get something like this to work across the board or know why on earth the business units are behaving so uniquely?

Answer

I’m doing something similar in a few of my email templates. Try something like this:

%%[ var @Title_Color
SET @Title_Color = "#1996e6"
]%%

...
<td class="title_text" align="center" style="font-size:20px; color: %%=Concat(@Title_Color)=%%;">[MY TITLE]</td>
...

EDIT: didn’t realize this was an old post. Sorry!

Attribution
Source : Link , Question Author : DigitalMC , Answer Author : dBelfiori

Leave a Comment