Code Block with Picklist

The heading tab selects a group of code panels, and the language picker selects which panel in that group is visible. Repeat a heading when its tab should offer multiple language or file choices.

Syntax

<CodeBlock slots="heading, code" repeat="4" languages="client.js, client.py, server.js, server.py" />

#### Client

```javascript
// client.js
```

#### Client

```python
# client.py
```

#### Server

```javascript
// server.js
```

#### Server

```python
# server.py
```

Parameters

Example

data-slots=heading, code
data-repeat=4
data-languages=client.js, client.py, server.js, server.py

Client

const response = await fetch('/api/items');
const items = await response.json();
console.log(items);

Client

from urllib.request import urlopen
import json

with urlopen('/api/items') as response:
    items = json.load(response)
    print(items)

Server

app.get('/api/items', async (request, response) => {
  const items = await getItems();
  response.json(items);
});

Server

@app.get('/api/items')
def list_items():
    return jsonify(get_items())

The Client tab offers client.js and client.py; the Server tab offers server.js and server.py. The displayed tab controls the picker choices, and the selected file label controls which code panel is shown.