---
title: code_block
description: "Create a fenced code block."
---

# code_block

Create a fenced code block.

## Syntax

```knap
{{ value | code_block }}
{{ value | code_block:"typescript" }}
```

## Usage

- Use this filter to explicitly create a code block. The `code` filter defaults to inline code using backticks, and automatically creates a fenced code block for multiline values or when a language is specified.
- The optional language is added after the opening fence.
- For arrays and objects, including serialized collections from another filter, string values are formatted recursively while keys and non-string values are preserved.

## Example

```json title="Data"
{
  "source": "const answer = 42"
}
```

```knap title="Template"
{{ source | code_block:"typescript" }}
```

````md title="Output"
```typescript
const answer = 42
```
````

## Related filters

- [code](/filters/code)
