ContentBlockByKey()
Returns the content contained in a content block from Content Builder by referencing its key.
This function only returns content that is in Content Builder. For Classic Content areas, use the ContentArea() function.
The ContentBlockByKey()
function has five parameters:
contentBlockKey
(string): Required. The key of the content block to retrieve.impressionRegionName
(string): The name of the impression region to associate with the content block.boolErrorOnMissingContentBlock
(boolean): Iftrue
, the function returns an error if the content block can’t be found. Iffalse
, the function doesn’t return an error. The default value istrue
.errorMessage
(string): The content to return if an error occurs while retrieving the content block.statusCode
(number): The exit code of the function. A value of0
indicates the function found the content block and successfully rendered the content. A value of-1
indicates either no content or an invalid content block.
To call the function, provide the unique key of the content block that you want to return.
If the function finds the content block, it returns the content in it. Otherwise, it returns an error message.
You can optionally begin an impression region when you insert the content block. This example inserts the content block with the key 4720e904-e9d0-4b0c-8a49-ecef280a3fa4 and creates an impression area called "bodytext" at the same time.
Use the EndImpressionRegion()
function to denote the end of the impression region.
You can use the status code parameter to show fallback content if the function wasn’t able to retrieve the content block.
If the specified content block is found, the function outputs the content of the content block. Otherwise, the function outputs the fallback message and the message shown in the If
statement.