Create Dynamic Subject Lines and Preheaders with AMPscript

Enabling Dynamic Subject Lines and Preheaders is easy with IF statements.

We previously talked about the conditional part of the IF statement as well as the syntax of the IF statement. But I wanted to walk you through one of my favorite uses of the IF statement – Dynamic Subject Lines and Preheaders.

Marketing Cloud actually processes your email body before it’s subject line and preheader fields. This means that we can set variables in the email body and call them in their respective fields.

To do this I need to set the variables in the body of my email by including this AMPscript block:

set @subjectline="Hello World!"
set @preheader="Look at me!"

And then I would call the variables in the subject line and preheader field like this:

All we need to do to make it dynamic is to have some sort of conditional logic that we can use in our IF statement.

For this example – we will use a field called @language to create our conditional logic.

The way the subject line an preheader field are filed in does not change. If will still contain: “%%=v(@subjectline)=%%” / “%%=v(@preheader)=%%” respectively.

The dynamic part comes from the block in the email body:

IF @language == "english" then
set @subjectline="Hello World!"
set @preheader="Look at me!"
elseif @language == "french" then
set @subjectline="Bonjour le monde!"
set @preheader="Regarde moi!"
elseif @language == "hindi" then
set @subjectline=="Namaste duniya!"
set @preheader=="mujhe dekho!"
else then
set @subjectline=="Hi Everybody!"
set @preheader=="I'm waving at you!"

In the example above I am using the variable @language to decide which translation they should get. One thing to note, If you are using an IF statement to set your Subject Line – ALWAYS have a fall back. This is set with the final “else”. In the example above the fall back is set to “Hi Everybody!” / “I’m waving at you!”

I’ve only got a few options in the example above, but you can do as many as you like.
I just didn’t want to type that many. Usually, when I have LOTS of options, I will use Lookup() and put all my values into a DE. Check back soon for a step by step on that option.

*IF the translations are wrong let me know. I used Google Translate.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.