0

I am trying to use an AMPscript variable to make some text in my footer section dynamic to our business units. I've created the field (@member_busname)in my test data extension and the variables I will need to reference in my code as follows:

%%[ VAR @member_busname, @x, @y, @foot_copy

SET @member_busname = member_busname

SET @x = 'if you no longer wish to receive ABCD association communications, <a href="%%unsub_center_url%%" style="color:#ffffff;">click here</a>'

SET @y = 'If you wish to be removed from this group's mailing list, <a href="%%unsub_center_url%%" style="color:#ffffff;">click here</a>'

%%[IF @member_busname == 'aa' THEN]%%
  SET @foot_copy = @x
  %%[ELSEIF @member_busname == 'ee' THEN]%%
  SET @foot_copy = @y
  %%[ENDIF]%%
  ]%% 

HTML footer section containing AMP variable to display

Errors: 1)I am placing this code within the head section of my HTML template, but the system doesn't seem to like it, it seems to associate the "%%" signs to other html code within the body.

2) I get these messages like: "Personalization error: The personalization string "%% %%" was not found in the following data extension(s)" and "Personalization error: The personalization string "%%<br>%%" was not found in the following data extension(s)." even though I have checked for any extra spaces or faulty elements.

I am not sure if placing the ampscript code within the head is incorrect or just something plainly wrong in my syntax, but if I don't wrap the if/elseif statement with the percentage signs like so, I will get an error stating that a closing "ENDIF" is missing even if it's there!

can anyone help me see my issue here? Thankyou.

  • if the code you provided is accurate you are missing a closing ]%% before your first if – EazyE Dec 13 '19 at 21:52
1

Although the proper opening %%[ is at the very beginning of the script, and the proper closing ]%% is at the very end of the script, blocks of AMPscript cannot be inside of another block (which is what is being done with every other %%[...]%% inside of the main block).

Also, when setting the @y variable, single quotes are being used, so the string is being cut off at the apostrophe in the word "group's". This is causing the single quote at the end of that line to actually be read as opening another string, which is causing the rest of the code to be seen as a string. This is most likely why you see an error stating that a closing ENDIF is missing. The way to get around this is by using double quotes to set text variables.

I generally like to keep the bulk of my AMPscript at the top of the email/page when feasible, but it really comes down to your coding style and use case.

That being said, it isn't necessary to have the <a href="%%unsub_center_url%%" style="color:#ffffff;">click here</a> included in the AMPscript, since that is just static html with the unsub_center_url personalization string.

I would try this:

%%[ 
VAR @member_busname, @foot_copy

SET @member_busname = member_busname

IF @member_busname == 'aa' THEN
  SET @foot_copy = "if you no longer wish to receive ABCD association communications"
ELSEIF @member_busname == 'ee' THEN
  SET @foot_copy = "If you wish to be removed from this group's mailing list"
ENDIF
]%% 

%%=v(@foot_copy)=%%, <a href="%%unsub_center_url%%" style="color:#ffffff;">click here</a>

I simplified the script a bit to set @foot_copy to the text directly, instead of setting extra variables. I also moved the html out of the AMPscript block and switched the possible @foot_copy values to use double quotes. I would expect that to fix the error stating that a closing ENDIF is missing (it was saying it was missing the ENDIF because it was seeing it as a text/string value, not AMPscript code).

Also, you may want to use a fallback as well, in case some of your subscribers are neither one of those member_busname's. That way those people will still get an Unsubscribe link.

Here's an example:

%%[ 
VAR @member_busname, @foot_copy

SET @member_busname = member_busname

IF @member_busname == 'aa' THEN
  SET @foot_copy = "if you no longer wish to receive ABCD association communications"
ELSEIF @member_busname == 'ee' THEN
  SET @foot_copy = "If you wish to be removed from this group's mailing list"
ELSE
  SET @foot_copy = "If you wish to be removed from this mailing list"
ENDIF
]%% 

%%=v(@foot_copy)=%%, <a href="%%unsub_center_url%%" style="color:#ffffff;">click here</a>
| improve this answer | |
  • thank you for your detailed response! 1)I was able to figure out my issues before being able to check back on here. I eliminated spacing errors by making sure I got rid of indentations in my ampscript. 2) I figured out there was an issue with using single quotes and switched to double quotes to remedy truncation issue. I also made the "click here" linked text static, rather than variable once I noticed the same thing as you and it all now works! Thank you for providing explanations! – nana-p Dec 16 '19 at 17:22
  • I did keep the extra variables in case this text ever changes I want to make the changes in the variables rather than hard code :) – nana-p Dec 16 '19 at 17:27
  • @nana-p That's great to hear. Please mark this as answered to help out anyone in the future with the same question. Thanks! – jake314159 Dec 16 '19 at 18:33
  • thank you, @jake314159! I have marked it so :) – nana-p Dec 17 '19 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.