2

Does anyone know why AMPscript variables won't work in the preheader? They will resolve in the send preview, but once the email is delivered they are blank.

If I use the same variables in both the subject line and preheader, the subject line variables resolve but the preheader variables do not once the email is delivered. This does not make sense to me and seems like a bug in SFMC. Wondering if anyone has a solution or work around.

These are ampscript variables... so the syntax is like this:

This is my variable: %%=v(@var)=%%

1
  • Are you initializing @var before assigning it? E.g. var @var set @var = "whee". Jan 19, 2016 at 13:36

3 Answers 3

5

The issue is that in the fully built email the AMPscript block that sets the preheader variables is placed farther down in the file than where the preheader gets inserted.

SFMC will place the preheader block directly after the opening <body> tag. In order to have preheader variables render after the email deployment, your AMPscript block that sets these variables must be placed before the opening <body> tag. I put the block directly after the opening <html> tag.

1

Perhaps this is the issue: missing <head></head> tags in your email.

Preheader doesn't render in a Marketing Cloud email

Found via findsf.info

Update

Relevant post: Create dynamic preheader in exacttarget

1
  • Thanks for the reply, this is pretty close but I figured out my issue which was something slightly different.
    – Jon Sakas
    Jan 22, 2016 at 18:45
0

In addition to the answers already given, and based on the same logic (code has to be executed before body), another option is to use inline ampscript directly in the preheader, which of course opens up the option to place your dynamic logic in a code snippet and reference it via inline ampscript: %%=ContentBlockByKey('myPreheader')=%% can go into the Preheader section, and then do whatever you like in that code snippet, e.g.

%%[
/* myPreheader codeSnippet */

SET @test = "123preheader"
/* build your lookups here ... */
]%%%%=v(@test)=%%

found this useful when using template-based emails, as the template often is the only place where you can access the area "before the body tag. A template change would of course be too global if you just want to set an individual preheader for one email.

3
  • I've used this workaround successfully before but for some reason I can't manage to get this to work again. I put the exact inline AMPScript in the preheader section (in the UI) with all my code in the referenced content block. I tried a code snippet and a html block but it doesn't make a difference. It looks like all variables are "forgotten" after the preheader rendered, when I try to reference them in the subject and in the body no variables render. Any pointers you can give that might cause this? Apr 12, 2022 at 22:41
  • Hi, please open a question with your code / screenshots, without seeing exactly what you see it's hard to tell. The order of operations which this workaround is based on is still the same, so I have no "systemic" indication why it wouldn't work: ampscript.guide/order-of-operations - I just retested it successfully, at least until the preview screen. Apr 13, 2022 at 6:52
  • Thanks for your reply. Posted my question here: salesforce.stackexchange.com/questions/373869/… Apr 14, 2022 at 12:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .