---
title: Far scegliere un template agli utenti
project: OpenTemplates
version: 1.0
section: recipes
language: it
license: MIT
url: https://totaljs.es/docs/it/opentemplates/1-0/recipes/template-picker/
updated: 2026-11-19T07:56:21.394Z
---

# Far scegliere un template agli utenti

> Mostra i template di OpenTemplates nella tua app e genera quello che sceglie un utente.

Quando la tua app offre più documenti, leggi l'elenco dei template da OpenTemplates invece di scrivere gli ID nel tuo codice. I nuovi template compaiono così nella tua app senza nessuna modifica.

**1.** Dai al token della tua app **Allow read list of profiles**. Leggi [Token API](../../guides/api-tokens/).

**2.** Leggi l'elenco e tieni il nome e l'ID di ogni template. Il codice gira dentro una funzione `async`:

```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 });
```

Con i dati della demo questo dà:

```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.** Mostra `label` all'utente. Quando l'utente ne sceglie uno, generalo con il suo `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` contiene il modello di esempio del template. Usalo per vedere quali campi si aspetta il template, o per compilare un'anteprima.

Leggi [Elencare profili e template](../../reference/profiles/).
