1

I'm trying to use ampscript to feed the subject line to the title tag on the webpage that loads when clicking on VAWP.

-I have the title tag set as <title>%%=v(@Subject_Line)=%%</title> in the head above body.

-In the AMPscript section in the header I have

%%[ VAR @Subject_Line 
  SET @Subject_Line = "Sample Subject Line" 
]%%

-I also have a %%[ if _MessageContext == "VAWP" or _MessageContext == "Social" or _MessageContext == "FTAF" then ]%% section to grab the VAWP from the send log

Set @Subject_Line = Lookup("Send Log","Subject_Line","SubID",@SubLookup,"JobID",@JobLookup,"BatchID",@BatchLookup).

The Subject_Line is passing to the send log as expected, and all the other content coming from the send log is populating correctly. Is this an order of operations issue, or does the VAWP only populate AMPscript in the body section of the content? I'm at a loss here.

3
  • Welcome to Salesforce Stack Exchange (SFSE). Your question has been edited to better highlight the code snippets. When asking or editing a question, please use the Markdown formatting available in the editor to make your post easier to read & follow (which makes it easier for folks to try to help). Use one backtick ( ` ) on either end of code used in-line, and three consecutive backticks ( ``` ) above & below a block of multi-line section of code. Inside of a code block, indention is retained, so it also helps to use consistent indentation for readability. Good luck getting an answer!
    – Moonpie
    Commented Sep 16, 2021 at 15:07
  • so ampscript renders from top to bottom, if you are setting the subject line after the title tag it will not reflect the subjectline
    – EazyE
    Commented Sep 16, 2021 at 15:30
  • Trying to find a workaround... I thought maybe because it was pulling from the send log it would populate. I added the ampscript in the head above the title tag and it did populate. The issue is this is being used on a custom template, so the template is locked to editing and we won't be able to write in the value Subject Line value - or at that point we would just hardcode it into the title tag. The only other alternative might be to pass it in the data extension and then just use a personalization field, but that's not really a viable alternative
    – Jeremy S.
    Commented Sep 16, 2021 at 15:59

1 Answer 1

0

Going off the comments, it sounds like your issue is:

  • You have a template that you want the Title tag to be the subject
  • This template is being used as a template and utilized in multiple places
  • The subject is set inside the emails using the template, not the template
    • meaning that the subject var value is set AFTER the title html is processed.
  • You want the title tag filled for VAWP.

So, for the email, this is impossible as AMPscript is a cascading language and works from top to bottom. So you cannot set a variable after it is called and have it output the new value.

BUT, the good news is you want to do this in the VAWP, not the email. There are a couple ways you can do this:

1. Use a send log to fill the var in the template:

%%[
    if _MessageContext == "VAWP"
      set @subject =  Lookup("sendlog","subject","jobid",jobid,"subscriberid",subscriberid)
    endif
]%%
<title>%%=v(@subject)=%%</title>

The sendlog will collect the subject (if you add the field subject and have a variable of same name in it) on send, so if you fill that prior to the calling of it in the template, it will grab the right subject.

2. VAWP link query parameter:

This one is pretty simple to do and remains within context so it might be easier to implement and avoids the potential processing draw if you have a significant volume in your send log.

%%[
    if _MessageContext == "VAWP"
      set @subject =  QueryParameter("sub")
    endif
]%%
<title>%%=v(@subject)=%%</title>

and then for where you have the VAWP link, you set it like this:

%%[
   set @subject = "my Subject"
   set @vawpLink = CONCAT(view_email_url,'&s=',URLEncode(@subject))
]%%
<a href="%%=RedirectTo(@vawpLink)=%%">view as webpage</a>

This does require the VAWP to be set after you set the subject though so depending where you have this link, this may not be viable.

2
  • Thanks @Gortonington, your first suggestion is what I already have in place - I send the subject to the send log, and have a lookup for VAWP, as well as having %%=v(@Subject_Line)=%% in my title tag. And my thought what that since it's VAWP it should work, but it doesn't for whatever reason. I also tried the second suggestion which also did not work for me.
    – Jeremy S.
    Commented Sep 17, 2021 at 15:55
  • @JeremyS. I have used both methods previously with success. It only works in the VAWP version though, not in the email. Remember this setting via the DE or Query String MUST be done above the title tag. It is still cascading processing despite coming from an outside source. Commented Sep 17, 2021 at 16:57

You must log in to answer this question.

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