Have you ever tried to insert AMPscript into a Free Form Content Block? Then you know for sure that they don’t like each other very much!
As a matter of fact, the WYSIWYG behind the Free Form formats the HTML every time we open the Free Form or when we click on the Content tab.
The formatting rules are strict and therefore every AMPscript line is seen as a simple line of text. The problem occur when we put our AMPscript inside an HTML tag that only accepts a particular tag as a child.
For example, the <ul> tag only accept <li> tag as a child and therefore the following code:
<ul> <li>Item 2</li> %%[ IF @v == 1 THEN ]%% <li>Item 2</li> %%[ ENDIF ]%% </ul>
Will result in this mess after closing and opening the Free Form or clicking on the Content tab:
<ul> <li> Item 2 </li> <li> %%[ IF @v == 1 THEN ]%%</li> <li> Item 2 </li> <li> %%[ ENDIF ]%%</li> </ul>
The solution is pretty simple! Just wrap your AMPscript code blocks in the HTML comment tags. In this way, the formatting will be ignored and the AMPscript will be executed properly.
<ul> <li>Item 2</li> <!--%%[ IF @v == 1 THEN ]%%--> <li>Item 2</li> <!--%%[ ENDIF ]%%--> </ul>
Have I missed anything?
Please poke me with a sharp comment below or use the contact form.