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.
Nice Trick & Tips ! Thanks
Not sure if it’s still an issue, but HTML comments used to cause problems with text-only versions of the email.
Thank you, I didn’t think of that and so far we didn’t receive any complaints… I’m going to put this to the test asap
I put my AMPscript in comments in a Free Form component and looked at the text preview.
Everything is fine.
Could you provide me with an example of where it could go wrong?