Verification in progress Differs from official docs Test scripts included

Syntax

ContentBlockByName(contentBlockName[, impressionRegionName, errorOnMissingContentBlock, errorMessage, statusCode])  →  string
1–5 arguments

Parameters

Name Type Required Description
contentBlockName string Yes Folder path and name of the content block, separated by backslashes
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 ContentBlockByName() with none, or with a sixth argument, cannot be saved.

Example

%%[
  VAR @sc, @out
  SET @out = ContentBlockByName("Content Builder\nosuch-name", "", 0, "Block unavailable", @sc)
]%%
%%=v(@out)=%%

The path 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 path 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. ContentBlockByName() 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. No matching block was set up 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 @cbn1 = ContentBlockByName("Content Builder\nosuch-name-zzz-it1", "", 0, "FB-CBN", @cbns1) ]%%%%=v(@cbn1)=%% %%=v(@cbns1)=%%

<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%[ SET @r2cbbynamel = ContentBlockByName("Content Builder\nosuch-name-zzz-it1", "", 0, "PRE-%%=Add(2,3)=%%-POST", @r2cbbynamels) ]%%%%=v(@r2cbbynamel)=%% %%=v(@r2cbbynamels)=%%

<!-- email 3: expect that the email saves, but the preview fails (HTTP 500) -->
%%[ SET @r2cbbynamef0 = ContentBlockByName("Content Builder\nosuch-name-zzz-it1", "", false, "FB-CBN", @r2cbbynamefs0) SET @r2cbbynamef1 = ContentBlockByName("Content Builder\nosuch-name-zzz-it1", "", "false", "FB-CBN", @r2cbbynamefs1) SET @r2cbbynamef2 = ContentBlockByName("Content Builder\nosuch-name-zzz-it1", "", "0", "FB-CBN", @r2cbbynamefs2) ]%%%%=v(@r2cbbynamef0)=%% %%=v(@r2cbbynamefs0)=%%|%%=v(@r2cbbynamef1)=%% %%=v(@r2cbbynamefs1)=%%|%%=v(@r2cbbynamef2)=%% %%=v(@r2cbbynamefs2)=%%

<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=ContentBlockByName()=%%

<!-- email 5: expect that the save is rejected (HTTP 400) -->
%%[ SET @r2cbbyname6 = ContentBlockByName("Content Builder\nosuch-name-zzz-it1", "", 0, "FB-CBN", @r2cbbyname6s, "extra") ]%%%%=v(@r2cbbyname6)=%%

<!-- email 6: expect that the email saves, but the preview fails (HTTP 500) -->
%%[ SET @r2cbbynamet = ContentBlockByName("Content Builder\nosuch-name-zzz-it1", "", 1, "FB-CBN", @r2cbbynamets) ]%%%%=v(@r2cbbynamet)=%%

Differs from official docs

  • A missing block fails the render despite a falsy flag. The reference says the flag false makes 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) with 0, and an email combining false, "false" and "0" also failed (not isolated per value), so neither the fallback nor the status code is ever used. Card

Availability & differences

PlatformAvailable
Marketing Cloud EngagementYes
Marketing Cloud NextYes, from API 67.0

See also