Adding AMPscript to Your Content
There are three ways to add AMPscript code to your content: by using inline code, by adding code blocks, or by using tag-based scripting. The first two of these methods use special delimiters to denote the beginning and ending of the code that you want Marketing Cloud Engagement to interpret. In the third method, you delineate the AMPscript code with
When you close an AMPscript block, use the same type of closing delimiter as you used to open the block. For example, if you open a block using tag-based scripting, you can't close it by using the closing code block delimiter.
=%% delimiters to add AMPscript code inline with your content. Inline AMPscript is frequently used within HTML tags to dynamically populate the content of a message. In this basic example, a section of AMPscript is included inline within an HTML
You can only execute a single function in a section of inline AMPscript. However, you can nest functions within an inline function. This example uses the
Iif() function to test a condition. In this case, the condition is whether the value of the variable
@var is empty, which is determined by using the nested
You can also include multi-line blocks of AMPscript code in your messages. Use the
]%% delimiters to begin and end a code block, respectively. With a code block, you can define multiple variables and execute multiple functions. Code blocks use the syntax shown in this example.
This example shows the complete syntax required to declare an AMPscript block.