Runtime verified Test scripts included

Syntax

ContentAreaByName(contentAreaName[, impressionRegionName, errorOnMissingContentArea, errorMessage, statusCode])  →  string
1–5 arguments

Parameters

Name Type Required Description
contentAreaName string Yes Folder path and name of the Classic content area to retrieve
impressionRegionName string No Impression region name to associate with the content area
errorOnMissingContentArea boolean No When true (the default), a missing area aborts; set to 0 to fall back to the default content
errorMessage string No Default content returned when the area is missing — emitted literally
statusCode number No Output variable set to 0 on success or -1 when no content was found

Example

%%[
  VAR @sc, @out
  SET @out = ContentAreaByName("nosuch\Folder\Area", "", 0, "Area unavailable", @sc)
]%%
%%=v(@out)=%%

Renders Area unavailable and sets @sc to -1 — the clean no-match path when the name does not resolve.

When the name does resolve, the bare form inserts the stored content area:

%%=ContentAreaByName('My Folder\My Content')=%%

Return value

string — the rendered HTML of the named content area, or the errorMessage default when the area is missing and errorOnMissingContentArea is 0. There is no closed set of sentinel values.

Behaviour

A missing name with the error flag set to 0 returns the default content. An unresolved folder-path name with errorOnMissingContentArea 0 renders the default content and sets the status variable to -1 instead of aborting the page.

The default content is emitted literally. A default containing an inline expression renders verbatim; the embedded AMPscript is not evaluated. Use TreatAsContent if the fallback string itself needs to run.

The function is still callable at runtime. Even though Classic content is retired, the call resolves and follows the documented default-content path rather than raising an unknown-function error.

Show test script
%%[
  VAR @b, @sc, @miss, @lit
  SET @b = RequestParameter("b")

  /* safe sweep: the missing/default paths are accepted and share one request */
  IF @b == "safe" THEN
    /* missing with error flag 0: returns the default content and sets status to -1 */
    SET @miss = ContentAreaByName("nosuch\Folder\Area", "", 0, "FB-CAN", @sc)
    OutputLine(Concat("miss=[", @miss, "] sc=[", @sc, "]"))

    /* default content is emitted literally - the inline AMPscript is NOT evaluated */
    SET @lit = ContentAreaByName("nosuch\Folder\Area", "", 0, "PRE-%%=Add(2,3)=%%-POST", @sc)
    OutputLine(Concat("lit=[", @lit, "]"))
  ENDIF
]%%

Availability

Platform Available
Marketing Cloud Engagement Yes (Classic content, deprecated)
Marketing Cloud Next No

See also