---
title: Generare un template
project: OpenTemplates
version: 1.0
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/opentemplates/1-0/reference/render/
updated: 2026-11-19T07:56:22.329Z
---

# Generare un template

> Invia dati a un template e ricevi indietro il documento finito.

```text
POST /
```

Invia l'ID del template e i dati in JSON. OpenTemplates compila il template, lo inserisce nel layout del suo profilo e risponde con il risultato.

## Richiesta

| Campo | Tipo | Cosa fa |
|---|---|---|
| `id` | string | Obbligatorio. L'ID del template: l'identificatore del profilo e l'identificatore del template, per esempio `demo/invoice`. |
| `data` | object | I dati del documento, disponibili come `value` nel template. Può essere anche una stringa JSON. Senza, il template riceve un oggetto vuoto. |
| `output` | string | `html` (il predefinito). `pdf`, `jpg` e `docx` richiedono un [token della Total.js API](../../guides/configuration/). |

Invia il token come descritto nella [Panoramica della REST API](../rest-api/).

## Esempio

```bash
curl -H "x-token: YOUR_TOKEN" -H "Content-Type: application/json" \
  -d '{"id":"demo/invoice","data":{"number":"2026-002","customer":"Jane Doe","items":[{"name":"Consulting","price":300}],"total":300}}' \
  https://templates.example.com/
```

La risposta è `200` con `Content-Type: text/html`:

```html
<!DOCTYPE html>
<html>
<head>
	<title>OpenTemplates</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<style>

		body, page { padding: 0; margin: 0; box-shadow: 0; background: #FFF; }

	</style>
</head>
<body>

	<page>
		<div style="padding:40px">
	<h1>Invoice 2026-002</h1>
	<p>Customer: <b>Jane Doe</b></p>
	<table style="width:100%;border-collapse:collapse">

		<tr><td style="padding:5px 0">Consulting</td><td style="text-align:right">300.00 &euro;</td></tr>

	</table>
	<p style="text-align:right">Total: <b>300.00 &euro;</b></p>
</div>
	</page>



</body>
</html>
```

Il modello di esempio e i blocchi degli helper del template e del layout non fanno parte del risultato.

## Inviare un modulo invece di JSON

L'endpoint accetta anche un modulo codificato come URL. Invia `data` come stringa JSON:

```bash
curl -H "x-token: YOUR_TOKEN" --data-urlencode "id=demo/welcome" --data-urlencode 'data={"name":"Jane"}' https://templates.example.com/
```

## Contatori e log

Ogni generazione aggiunge uno ai contatori del profilo e del template e scrive una [voce di log](../../guides/logs/).

## Errori

Un `id` mancante risponde `400` con `[{"error":"Invalid template ID"}]`, e un ID di template sconosciuto risponde `400` con `[{"error":"Template not found"}]`. Leggi [Errori](../errors/).
