Beginner • SFMC

AMPscript Basics for Salesforce Marketing Cloud

Learn the core AMPscript building blocks for personalization, conditional logic, and dynamic content in emails, landing pages, and content blocks.

4 core AMPscript concepts Practical SFMC examples Great for marketers and developers

What you will learn

AMPscript helps you personalize content and add logic to your Marketing Cloud assets.

Personalize content

Display a subscriber’s first name, email address, or attributes directly in your content.

Use simple logic

Apply IF/ELSE conditions to show different content based on subscriber data.

Build dynamic blocks

Switch content sections using data-driven rules and audience attributes.

Work with data extensions

Read values from Data Extensions and use them within emails and landing pages.

Core AMPscript concepts

1. Script blocks

AMPscript is wrapped in script tags like %%[ ... ]%% so SFMC can process it during send or render.

2. Output values

Use Output() to display values such as first names, product names, or promo codes.

3. Conditional logic

Use IF/ELSE to decide what content should appear based on subscriber data.

4. Variables

Store values in variables to reuse them in your email or landing page content.

Beginner examples

Example 1: Personalize the greeting

%%[
  SET @firstName = AttributeValue("FirstName")
  IF NOT EMPTY(@firstName) THEN
    SET @greeting = Concat("Hello ", @firstName)
  ELSE
    SET @greeting = "Hello there"
  ENDIF
]%%

<p>%%=v(@greeting)=%%</p>

Example 2: Show a special offer

%%[
  SET @country = AttributeValue("Country")
  IF @country == "US" THEN
    SET @offer = "Free shipping on orders over $50"
  ELSE
    SET @offer = "Free shipping on orders over $75"
  ENDIF
]%%

<p>%%=v(@offer)=%%</p>

Example 3: Display a dynamic link

%%[
  SET @productName = "Spring Collection"
  SET @link = Concat("https://example.com/products/", Lowercase(@productName))
]%%

<a href="%%=RedirectTo(@link)=%%">View %%=v(@productName)=%%</a>

AMPscript FAQs

What is AMPscript used for in Salesforce Marketing Cloud?

AMPscript personalizes and controls content in Marketing Cloud messages and pages, such as inserting subscriber attributes or choosing content with conditional logic.

Where can I use AMPscript?

You can use AMPscript in supported Marketing Cloud email, landing page, and content-block contexts. The data available to a script depends on the context in which the content is rendered.

How should I test an AMPscript snippet?

Test with representative subscriber data in the appropriate Marketing Cloud preview or test-send context, and check both populated and missing-attribute cases. The SFMCpulse playground is for practice and does not connect to a live account.

Mini roadmap for your first week

Ready to practice?

Try your own AMPscript snippets and personalize content in the interactive playground.

Book a 1:1 Session