---
title: Riferimento del file del widget
project: Total.js CMS
version: 1.0
section: development
language: it
license: MIT
url: https://totaljs.es/docs/it/cms/1-0/development/widget-file-api/
updated: 2026-11-20T06:51:42.966Z
---

# Riferimento del file del widget

> Cosa dichiara un widget nel suo script del server.

Lo script del server è la sezione `<script total>` del widget. Il CMS lo esegue quando installa, modifica o carica il widget, e legge queste proprietà e funzioni da `exports`.

Le voci di tipo **property** sono valori che imposti tu. Le voci di tipo **event** sono funzioni che definisci tu e che il CMS chiama.

## API

### exports.id = 'greeting';

Type: `property`

L'identificatore del widget.

Returns: `String`

Le pagine fanno riferimento al widget tramite questo valore, e `CLASS` diventa `w-` seguito dall'identificatore senza trattini. Un widget salvato con l'identificatore di un widget installato lo sostituisce. Senza `id`, il CMS usa `name` come identificatore.

### exports.name = 'Greeting';

Type: `property`

Il nome mostrato nell'amministrazione e nel selettore dei widget.

Un widget senza nome non viene installato.

### exports.author = 'Jane Doe';

Type: `property`

L'autore del widget.

### exports.version = '1';

Type: `property`

La versione del widget, come testo.

### exports.preview = 'data:image/png;base64,...';

Type: `property`

L'immagine del widget nell'amministrazione.

Un URI `data:` o un indirizzo. Il CMS scarica un'immagine `https://` tra i suoi file quando salva il widget. Vedi [Stili, script e risorse](../styles-and-assets/#preview-image).

### exports.config = { name: 'World', align: 'left' };

Type: `property`

La configurazione predefinita di una nuova istanza.

L'editor la copia in ogni istanza che l'utente aggiunge. Vedi [Le impostazioni e il loro modulo](../settings/).

### exports.dependencies = ['https://example.com/lib.css', 'https://example.com/lib.js'];

Type: `property`

File che il CMS aggiunge all'head di ogni pagina pubblica.

Un array o una stringa separata da virgole o punti e virgola. Un indirizzo che termina con `.css` diventa un `<link>`, uno che termina con `.js` diventa uno `<script>`, e un valore con `<` viene aggiunto così com'è.

### exports.cache = 'url';

Type: `property`

Conserva un risultato in cache per ogni indirizzo.

Con il valore `url`, un risultato di `render` in cache viene conservato separatamente per ogni indirizzo di pagina. È importante per i widget in un layout. Vedi [Il rendering sul sito pubblico](../rendering/#cache).

### exports.render = function(opt, next) {}

Type: `event`

Genera il contenuto di un'istanza sul sito pubblico.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `opt` | `Object` | yes |  | L'istanza e la richiesta. Vedi il [Riferimento di render](../render-api/). |
| `next` | `Function` | yes |  | `next(content, [replace], [cache])`. Vedi il [Riferimento di render](../render-api/#next). |

Viene chiamata per ogni istanza ogni volta che la pagina viene costruita, a meno che non esista un risultato in cache. Non viene chiamata nell'editor.

Example: Aggiungere il caricamento differito alle immagini dell'istanza
```js
exports.render = function(opt, next) {
	next(opt.html.replace(/<img\s/g, '<img loading="lazy" '), false, true);
};
```

### exports.install = function(db) {}

Type: `event`

Viene eseguita quando il CMS installa, aggiorna o carica il widget.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `db` | `Object` | yes |  | I dati del CMS, con `vars`, `config` e `storage`. È anche `this`. |

Vedi [Installazione e disinstallazione](../install-hooks/).

Example: Creare una variabile con un valore predefinito
```js
exports.install = function(db) {
	if (!db.vars.supportemail)
		db.vars.supportemail = 'help@example.com';
};
```

### exports.uninstall = function(db) {}

Type: `event`

Viene eseguita quando il widget viene rimosso e prima che venga aggiornato.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `db` | `Object` | yes |  | I dati del CMS. È anche `this`. |

Vedi [Installazione e disinstallazione](../install-hooks/).
