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.