ContentAreaByName
Inserts a Classic content area by its folder path and name. Covers the no-match default path and that default content is emitted literally. Classic content is retired; prefer ContentBlockByName.
Syntax
ContentAreaByName(contentAreaName[, impressionRegionName, errorOnMissingContentArea, errorMessage, statusCode]) → string
ContentAreaByName references Classic content areas, which are no longer supported. Author new content in Content Builder and retrieve it with ContentBlockByName.
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 |
string | boolean | number | No | When truthy (the default), a missing area aborts; when falsy, the page continues and the status variable is set to -1. Accepts true, false, 1, 0, "true", "false", "1", "0" |
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.
All eight boolean-like literals are accepted for errorOnMissingContentArea. true, false, 1, 0, "true", "false", "1", "0" are interchangeable: when the area is missing, a truthy value aborts the page with HTTP 422 while a falsy value lets it continue at HTTP 200 and sets the status variable to -1.
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
]%%
OutputLine given a bare string literal renders an empty line. Wrap the argument in Concat() or your start and done markers vanish silently — which looks exactly like the function failing.
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes (Classic content, deprecated) |
| Marketing Cloud Next | No |
See also
ContentArea— the same Classic lookup keyed by numeric IDContentBlockByKey— the Content Builder replacement keyed by customer key- Official reference
- ampscript.guide