AMPscript ContentBlockByKey (Next)
Load a content block by customer key with AMPscript ContentBlockByKey in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including the missing-block fallback that breaks the render.
Syntax
ContentBlockByKey(contentBlockKey[, impressionRegionName, errorOnMissingContentBlock, errorMessage, statusCode]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contentBlockKey |
string | Yes | Key that identifies the content block to insert |
impressionRegionName |
string | No | Name of an impression region that the inserted block is tracked under |
errorOnMissingContentBlock |
string | boolean | number | No | Error flag. In Next a missing block fails the render with any value tested: 1, 0, false, "false", "0" |
errorMessage |
string | No | Fallback text for a missing block; in Next the render fails before it is used |
statusCode |
number | No | Output variable for the lookup status; not observed in Next, as the render fails first |
One to five arguments: an email that calls ContentBlockByKey() with none, or with a sixth argument, cannot be saved.
Example
%%[
VAR @sc, @out
SET @out = ContentBlockByKey("nosuch-key", "", 0, "Block unavailable", @sc)
]%%
%%=v(@out)=%%
The key nosuch-key does not exist. In Next this email saves and publishes, but the preview fails (HTTP 500) instead of rendering Block unavailable. Only reference blocks that exist.
Return value
string — meant to be the rendered block. Loading a block that exists was not tested in Next, so no return value has been observed.
Behaviour
A missing block fails the render, whatever the error flag. With the flag 0, false, "false" or "0", a key that does not exist makes the preview fail (HTTP 500) instead of returning the fallback text. The flag 1 fails the same way.
The fallback text is never reached. A fallback containing %%=Add(2,3)=%% also ends in a failed render, so whether it would be evaluated or printed as written is unknown in Next.
The argument count is checked at save. ContentBlockByKey() and a six-argument call are both refused with HTTP 400 and “The AMPscript syntax isn’t valid”.
Loading an existing block was not tested in Next. The test block used on Engagement does not exist in the Next org, so rendering a found block and the status code on success are both unproven.
Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
would stop the whole preview or block the save. -->
<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
%%[ SET @cbk1 = ContentBlockByKey("nosuch-key-zzz-it1", "", 0, "FB-CBK", @cbks1) ]%%%%=v(@cbk1)=%% %%=v(@cbks1)=%%
<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%[ SET @r2cbbykeyl = ContentBlockByKey("nosuch-key-zzz-it1", "", 0, "PRE-%%=Add(2,3)=%%-POST", @r2cbbykeyls) ]%%%%=v(@r2cbbykeyl)=%% %%=v(@r2cbbykeyls)=%%
<!-- email 3: expect that the email saves, but the preview fails (HTTP 500) -->
%%[ SET @r2cbbykeyf0 = ContentBlockByKey("nosuch-key-zzz-it1", "", false, "FB-CBK", @r2cbbykeyfs0) SET @r2cbbykeyf1 = ContentBlockByKey("nosuch-key-zzz-it1", "", "false", "FB-CBK", @r2cbbykeyfs1) SET @r2cbbykeyf2 = ContentBlockByKey("nosuch-key-zzz-it1", "", "0", "FB-CBK", @r2cbbykeyfs2) ]%%%%=v(@r2cbbykeyf0)=%% %%=v(@r2cbbykeyfs0)=%%|%%=v(@r2cbbykeyf1)=%% %%=v(@r2cbbykeyfs1)=%%|%%=v(@r2cbbykeyf2)=%% %%=v(@r2cbbykeyfs2)=%%
<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=ContentBlockByKey()=%%
<!-- email 5: expect that the save is rejected (HTTP 400) -->
%%[ SET @r2cbbykey6 = ContentBlockByKey("nosuch-key-zzz-it1", "", 0, "FB-CBK", @r2cbbykey6s, "extra") ]%%%%=v(@r2cbbykey6)=%%
<!-- email 6: expect that the email saves, but the preview never shows the new version (no fresh render) -->
%%[ SET @r2cbbykeyt = ContentBlockByKey("nosuch-key-zzz-it1", "", 1, "FB-CBK", @r2cbbykeyts) ]%%%%=v(@r2cbbykeyt)=%%
Differs from official docs
- A missing block fails the render despite a falsy flag. The reference says the flag
falsemakes the function return the fallback text and set the status code to-1. In Next, a block that does not exist made the preview fail (HTTP 500) with0, and an email combiningfalse,"false"and"0"also failed (not isolated per value), so neither the fallback nor the status code is ever used. Card
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
For a key that does not exist with the error flag 0, Engagement returns the fallback text and sets the status variable to -1 (FB-CBK -1); in Next the same email fails to render (HTTP 500). The falsy spellings false, "false" and "0" fail the same way in Next. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
ContentBlockByID— retrieve a block by its numeric IDContentBlockByName— retrieve a block by its folder path and name- Official reference