0

I will need a few AMPScript variables in a template. The same variables will be used in several templates thought I would write a file that populates them and use some include function the way one does in html. Now I wonder if:

  1. It's possible at all
  2. The variables defined in the script will be accessible to other content elements in the template.
1

You can definitely do that.

I'm working on an email right now that initializes and sets base AMPScript variables in the template and then overrides the values in the email.

Template

%%[
var @bodyStyle, @footerColor
set @bodyStyle = "style='background-color:green'"
set @footerColor = "#ffffff"
]%%
<custom type="content" name="init">
<html>
 <head></head>
 <body %%=v(@bodyStyle)=%%>
  <div id="footer" style="background-color:%%=v(@footerColor)=%%">
  </div>
 </body>
</html>

Email Init Content Area

%%[
if @whatever == "whee" then
  set @bodyStyle = "style='background-color:green'"
  set @footerColor = "#666666"
endif
]%%

You can also dynamically retrieve a stored Content Area and reference it with the ContentAreaByName() function. The Content Area can contain whatever scripting you need.

| improve this answer | |
  • Thank you I already have the template created from a wizard and I can not modify it. I saw the ContentAreasByName in other post but I didn't know how to use it so I intuitively turned to researching server side javascript. SO can I just use %%=ContentAreaByName(@contentPath)=%% to load the content and then reference the variables? I will test – user682217 Mar 22 '16 at 8:18

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.