---
title: Your first widget
project: CMS
version: 1.0
section: development
language: en
license: MIT
url: https://totaljs.es/docs/cms/1-0/development/first-widget/
updated: 2026-11-19T11:56:27.963Z
---

# Your first widget

> Create a widget in the admin, add it to a page and change its settings.

This example creates **Greeting**: a framed line with an editable word and a name that the user sets in the settings.

## Create the widget

1. Open **Widgets**.
2. Click **Options** and choose **Create**. The **Source-code** window opens with a template of a new widget.
3. Replace the whole text with the code below and click **SUBMIT**.

![The Source-code window with the template of a new widget](/files/Jaq7WN1o161f.webp)

```html
<script total>

	exports.id = 'greeting';
	exports.name = 'Greeting';
	exports.author = 'Jane Doe';
	exports.version = '1';
	exports.config = { name: 'World', align: 'left' };

</script>

<style>
	.CLASS-box { padding: 20px; border: 1px solid #E0E0E0; border-radius: var(--radius); font-size: 18px; }
	.CLASS-center { text-align: center; }
</style>

<settings>
	<div class="padding">
		<div class="m">
			<ui-component name="input" path="?.name" config="required:1">Name</ui-component>
		</div>
		<ui-component name="input" path="?.align" config="dirsource:left|Left,center|Center">Align</ui-component>
	</div>
	<script>
		exports.save = function(config, el) {
			var box = el.find('.CLASS-box');
			box.find('b').text(config.name);
			box.tclass('CLASS-center', config.align === 'center');
		};
	</script>
</settings>

<body>
	<div class="CLASS-box"><span class="CMS_edit">Hello</span> <b>World</b></div>
</body>
```

**Greeting** appears on the **Widgets** screen. A widget without a preview image shows an empty picture there.

The identifier `greeting` must be unique. If another widget already has it, saving replaces that widget.

## Add it to a page

1. Open a page in the [visual editor](/cms/1-0/guides/visual-editor/).
2. Click the content area and choose **Add a widget**.
3. Click **Greeting**.

![The Greeting widget in the visual editor, with the floating panel above the editable word Hello](/files/Jaq7WP1p160f.webp)

The word **Hello** has the class `CMS_edit`, so the user can click it and choose **Edit** to change it. **World** has no such class: it changes only through the settings.

## Change the settings

1. Click the widget and choose **Widget settings**, the gear button.
2. Enter a name and choose **Center** in **Align**.
3. Click **APPLY**.

![The Configuration window of Greeting with the Name and Align fields and the four options to hide the widget](/files/Jaq7WR1q161f.webp)

The function `exports.save` writes the name into the `b` element and adds the class for the alignment. CMS stores the values in the page with the instance. **Save** the page.

## See it on the public site

Open the page. The visitor sees the frame and the text:

```html
<div class="w-greeting CMS_mv CMS_mh" data-cms-id="mwnhgevf">
	<div class="w-greeting-box"><span>Hello</span> <b>World</b></div>
</div>
```

CMS removes the `CMS_` classes of the editor and the `data-cms` attribute. It keeps the margins `CMS_mv` and `CMS_mh` and the class of the widget.

## Change the widget

On the **Widgets** screen, click **Greeting** (or its gear button and **Edit**). Change the code and click **SUBMIT**. CMS compiles the widget again, and every page uses the new styles, settings and server code at once.

Keep the same `exports.id` when you edit a widget. Pages refer to the widget by its identifier, and an instance whose widget does not exist is left out of the public page. The editor also removes such instances when it opens the page.
