ContentBlockByName

This function returns the content stored in the specified Content Block and optionally wraps the content in an Impression Region.

Arguments

ContentBlockByName(1,2,3,4,5)

Ordinal Type Required Description
1 String True The full path of the content block to return
2 String False Name of the Impression Region to associate with this Content Area
3 Boolean False Return an error if the Content Area cannot be found
4 String False Default content if an error occurs retrieving the content block specified in Ordinal 1
5 Number False Numeric status code resulting from the retrieve. A value of 0 indicates the retrieve was successful, while -1 indicates that the content was not found or empty.

NOTE: This function is only for use with Content Builder assets. It does not retrieve content stored in Classic Content. To retrieve content from Classic Content by name, use the ContentAreaByName function.

Example 1

A Content Block named LoyaltyGreeting in the Content Builder folder contains the following code:

%%[

var @firstName
set @firstName = properCase(AttributeValue("FirstName"))

]%%
Hello, %%=v(@firstName)=%%!

The Content Block can be referenced as:

%%[

var @contentBlockName
set @contentBlockName = "Content Builder\LoyaltyGreeting"

]%%
%%=ContentBlockByName(@contentBlockName)=%%

Output

Hello, Curt!

Example 2

A Content Block named LoyaltyGreeting in the Content Builder folder contains the following code:

%%[

var @firstName
set @firstName = properCase(AttributeValue("FirstName"))

]%%
Hello, %%=v(@firstName)=%%!

In the scenario where the Content Block does not exist, fallback content is handled with the value of the fourth argument or by conditionally showing content based on the value of the @retrieveStatus variable:

%%[

var @contentBlockName, @content, @retrieveStatus
set @contentBlockName = "Content Builder\LoyaltyGreeting_Oops" /* does not exist */
set @content = ContentBlockByName(@contentBlockName, "Greeting", 0, "Hello!", @retrieveStatus)

output(concat(@content))

if @retrieveStatus < 0 then
  output(concat('<br><br><a href="https://limedash.com/join">Join Now</a> &raquo;'))
endif

]%%

Output

Hello!

<a href="https://limedash.com/join">Join Now</a> &raquo;