---
title: Let users pick a template
project: OpenTemplates
version: 1.0
section: recipes
language: en
license: MIT
url: https://totaljs.es/docs/opentemplates/1-0/recipes/template-picker/
updated: 2026-11-19T07:56:21.394Z
---

# Let users pick a template

> Show the templates of OpenTemplates in your app and render the one a user picks.

When your app offers several documents, read the list of templates from OpenTemplates instead of typing the IDs into your code. New templates then show up in your app without a change.

**1.** Give the token of your app **Allow read list of profiles**. See [API tokens](../../guides/api-tokens/).

**2.** Read the list and keep the name and the template ID of each template. The code runs inside an `async` function:

```js
const URL = 'https://templates.example.com';
const headers = { 'x-token': process.env.OPENTEMPLATES_TOKEN };

const profiles = await (await fetch(URL + '/profiles/', { headers })).json();
const choices = [];
for (const profile of profiles)
	for (const template of profile.templates)
		choices.push({ label: profile.name + ' / ' + template.name, id: template.reference, model: template.model });
```

For the demo data this gives:

```text
Demo project / Invoice -> demo/invoice
Demo project / Welcome letter -> demo/welcome
Demo project / Receipt -> demo/receipt
Demo project / Credit note -> demo/creditnote
Letters / Welcome letter -> letters/welcome
```

**3.** Show `label` to the user. When the user picks one, render it with its `id`:

```js
const html = await (await fetch(URL + '/', {
	method: 'POST',
	headers: { ...headers, 'content-type': 'application/json' },
	body: JSON.stringify({ id: choice.id, data: yourData })
})).text();
```

`model` holds the sample model of the template. Use it to see which fields the template expects, or to fill a preview.

See [List profiles and templates](../../reference/profiles/).
