Building templates for a client in CONTENT BUILDER and we're using AMPscript at the top so a non-HTML user can insert the content they want to populate in the email.
Everything works great, until the customer wants to include a URL in the copy, as the SET statements get messy since the quotes in the a href close the SET statement.
We've tried using TreatAsContent, but did not have much luck as we couldn't get the URLs to get tracked. Here are a few things we tried.
SET @sub_trailer = "Lean more by clicking <a href="http://www.google.com">here</a>"
The above results in the URL missing and the code breaking, since the SET statement ends after the href="
We also tried
SET @link = "http://www.google.com"
SET @sub_trailer = "Learn more by clicking <a href="%%=RedirectTo(@link)=%%">here</a>
and that has the same issue as above.
We also tried the above and in the email itself using %%=TreatAsContent(@sub_trailer)=%%
using the escape codes for the quotation marks SET @sub_trailer = "Learn more by clicking <a href=%22%%=RedirectTo(@link)=%%%22>here</a>
, and while the content appears, the link doesn't track and it becomes "http://www.google.com" instead of just http:// and obviously it's not tracked.
We ended up simply pasting over the AMPscript displayed in the email (where %%=v(@sub_trailer)=%% appears)
Best Answer
There are a couple solutions to this:
Using single quote (but keep in mind, this limits the content as well, e.g. Ronald's car would cause the same issue as your current double quote issue.
SET @sub_trailer = 'Learn more by clicking <a href="%%=RedirectTo(@link)=%%">here</a>'
Utilizing CONCAT()
This will let you separate ampscript variables, and different sections of content from the overlying container.
SET @link = "http://www.example.com" SET @sub_trailer = CONCAT('Learn more by clicking <a href="', RedirectTo(@link), '">here</a>')
So the best way I have found to do this is not really best practice at all, but it works.
You would wrap the whole thing in a TreatAsContentArea() function. You would have the 'name' of the content area be a variable that is unique to each email, to get around the weird 100 limitation that they have on it. Sample below:
SET @sub_trailer = TREATASCONTENTAREA(Concat(emailaddr, "_sub_trailer"), 'Learn more by clicking <a href="%%=RedirectTo(@link)=%%">here</a>')
You then have to call it inside the HTML using the TreatAsContent() function (no idea why...).
%%=TreatAsContent(@sub_trailer)=%%
As I said, this is not best practice and can have repurcussions on execution run time, but it is really the ONLY way I have found that can get around this issue.