Order of Operations
Like other scripting languages, AMPscript is interpreted from top to bottom, which means that variables have to be declared and set before they can be used. However, email components are interpreted in the following order:
- email preheader
- HTML body
- text body
- subject line.
For example, a variable can be declared and set in an HTML body (within an AMPscript block), then used in a subject line:
<!--Appears in Body--> %%[ var @subjectLine if AttributeValue('Member Status') == 'VIP' then set @subjectLine = 'An exclusive offer for VIP members' else set @subjectLine = 'A special offer for our members' endif ]%% <!--Appears in Subject Line--> %%=v(@subjectLine)=%%