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

# Widget file reference

> What a widget declares in its server script.

The server script is the `<script total>` section of the widget. CMS runs it when it installs, edits or loads the widget, and reads these properties and functions from `exports`.

Entries of type **property** are values that you set. Entries of type **event** are functions that you define and CMS calls.

## API

### exports.id = 'greeting';

Type: `property`

The identifier of the widget.

Returns: `String`

Pages refer to the widget by this value, and `CLASS` becomes `w-` plus the identifier without dashes. A widget saved with the identifier of an installed widget replaces it. Without `id`, CMS uses `name` as the identifier.

### exports.name = 'Greeting';

Type: `property`

The name shown in the admin and the widget picker.

A widget without a name is not installed.

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

Type: `property`

The author of the widget.

### exports.version = '1';

Type: `property`

The version of the widget, as text.

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

Type: `property`

The picture of the widget in the admin.

A `data:` URI or an address. CMS downloads an `https://` picture into its files when it saves the widget. See [Styles, scripts and assets](../styles-and-assets/#preview-image).

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

Type: `property`

The default configuration of a new instance.

The editor copies it into each instance that the user adds. See [Settings and their form](../settings/).

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

Type: `property`

Files that CMS adds to the head of every public page.

An array or a string separated by commas or semicolons. An address that ends with `.css` becomes a `<link>`, one that ends with `.js` becomes a `<script>`, and a value with `<` is added as it is.

### exports.cache = 'url';

Type: `property`

Keeps one cached result for each address.

With the value `url`, a cached `render` result is kept separately for each page address. It matters for widgets in a layout. See [Rendering on the public site](../rendering/#cache).

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

Type: `event`

Makes the content of an instance on the public site.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `opt` | `Object` | yes |  | The instance and the request. See [Render reference](../render-api/). |
| `next` | `Function` | yes |  | `next(content, [replace], [cache])`. See [Render reference](../render-api/#next). |

Called for each instance each time the page is built, unless a cached result exists. Not called in the editor.

Example: Add lazy loading to the images of the instance
```js
exports.render = function(opt, next) {
	next(opt.html.replace(/<img\s/g, '<img loading="lazy" '), false, true);
};
```

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

Type: `event`

Runs when CMS installs, updates or loads the widget.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `db` | `Object` | yes |  | The CMS data, with `vars`, `config` and `storage`. It is also `this`. |

See [Install and uninstall](../install-hooks/).

Example: Create a variable with a default value
```js
exports.install = function(db) {
	if (!db.vars.supportemail)
		db.vars.supportemail = 'help@example.com';
};
```

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

Type: `event`

Runs when the widget is removed and before it is updated.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `db` | `Object` | yes |  | The CMS data. It is also `this`. |

See [Install and uninstall](../install-hooks/).
