---
schema_version: "1"
id: efaa51068557911abae2c08ed9bccf85d7341fb4653f0bbd1bba9adfb1cc1049
title: ContentBlockByKey()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/content/mc-ampscript-reference-content-block-by-key.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-block-by-key.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5dec4fd2a53a51546455d56934c670739b8861b1a56f1187c6ea981078f133db
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# ContentBlockByKey()

Returns the content contained in a content block from Content Builder by referencing its key.

In Marketing Cloud Engagement, this function returns content from Content Builder. For Classic Content areas, use the [ContentArea()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-area.md) function.

In Marketing Cloud Next, the function retrieves a content block from the Marketing Content Management System by its content key. If more than one version of the content block is available, the function retrieves the version that was published most recently.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>✅ Yes</td>
  </tr>
</table>

This function became available in Marketing Cloud Next during the Summer ’26 release (API version 67.0).

## Syntax

```
ContentBlockByKey(contentBlockKey,
                  impressionRegionName,
                  boolErrorOnMissingContentBlock,
                  errorMessage, statusCode)
```

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): If `true`, the function returns an error if the content block can’t be found. If `false`, the function doesn’t return an error. The default value is `true`.
- `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 of `0` 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.

## Usage

To call the function, provide the unique key of the content block that you want to return.

```
%%[
  Set @ContentBlockKey = "4720e904-e9d0-4b0c-8a49-ecef280a3fa4"
]%%
<p>%%=ContentBlockByKey(@ContentBlockKey)=%%</p>

```

If the function finds the content block, it returns the content in it. Otherwise, it returns an error message.

### Adding an Impression Region

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.

```
%%[
  Set @ContentBlockKey = "4720e904-e9d0-4b0c-8a49-ecef280a3fa4"
]%%
<p>%%=ContentBlockByKey(@ContentBlockKey, "bodytext")=%%</p>
```

Use the `EndImpressionRegion()` function to denote the end of the impression region.

### Using the Status Code

You can use the status code parameter to show fallback content if the function wasn’t able to retrieve the content block.

```
%%[
Var @Content, @ContentBlockKey, @StatusCode
Set @ContentBlockKey = "4720e904-e9d0-4b0c-8a49-ecef280a3fa4"
Set @Content = ContentBlockByKey(@ContentBlockKey, "bodytext", false, "We're sorry, but something went wrong... ", @StatusCode)

Output(@Content)

If @StatusCode == -1 then
Output(Concat('Visit the <a href="https://www.example.com/help">Example.com Help Pages</a> for more information.'))
EndIf
]%%
```

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.

## See Also

- [ContentArea()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-area.md)
- [ContentBlockById()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-block-by-id.md)
- [ContentBlockByName()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-block-by-name.md)
- [EndImpressionRegion()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-end-impression-region.md)
