Skip to main content

Script Declarations

Script Declarations allow you to inject code before the <!DOCTYPE html> declaration in your email's exported HTML. This is required for scripting languages like AMPscript (Salesforce Marketing Cloud) and similar pre-DOCTYPE syntaxes, where variable declarations must appear at the very top of the HTML document before any tags.


What is it and why is it important?

When building emails for ESPs like Salesforce Marketing Cloud, some dynamic content features — such as AMPscript variable declarations — must be placed before the HTML document starts. Standard code injection fields in Stensul (Custom Head Code, Prepend/Append Code) insert content inside the <head> or <body> tags, which does not meet this requirement.

Script Declarations solve this by letting admins define a default block of code at the library level, and letting email builders override that code per email. On export, this code appears at the very top of the HTML output — before <!DOCTYPE html>.

Example use case: Declaring AMPscript variables for dynamic personalization in SFMC.

%%[ VAR @firstName SET @firstName = AttributeValue("First Name") ]%%


What permissions are needed?

The access_script_declarations permission is required for:

  • Admins to enable the feature in Library Settings and set a library-level default

  • Email builders to view and edit script declarations in the Email Builder

Assign this permission to any role that should have access. Contact your Stensul administrator if you do not see the Script Declarations option.


How does it work and what can it do?

For Admins — Library Settings

  1. Open the Library Builder and navigate to the Advanced Settings tab.

  2. Locate the Script Declarations section.

  3. Enable the Enable script declarations toggle.

  4. Click Script declarations to open the code editor.

  1. Enter the default pre-DOCTYPE code for this library (e.g. AMPscript variable declarations).

  2. Click Save to store the code as the library default.

Once enabled, email builders with the access_script_declarations permission will see an option to edit declarations in their emails.

For Email Builders — Email Builder

  1. Open an email in the Email Builder.

  2. Go to Advanced Settings.

  1. If script declarations are enabled for the library, an Edit script declarations button will appear.

  2. Click the button to open the code editor. It opens pre-populated with the library's default code.

  1. Edit the code as needed for this specific email.

  2. Click Save to apply your changes.

The email-level code takes priority over the library default on export.

On Export

Scenario

Code injected

Library default set, no email-level override

Library default code

Email-level code set

Email-level code (library default is ignored)

No code set at either level

Nothing injected

Note: Script declarations are not visible in the in-browser preview — they are only present in the exported HTML.

When Cloning an Email

Script declarations are carried over when you clone an email. If the source email had no email-level override, the clone will continue to use the library default.


Want more help? Have no fear, your Stensul team is here! Please email us at [email protected].

Did this answer your question?