---
title: Show toasts and modals
description: Tell the user what your Volumio plugin did with a toast, or ask them to decide with a modal window that can call a method of your plugin.
---

Tell the user what your plugin did with a toast, or ask them to decide with a modal window. A toast appears for a few seconds and needs no answer. A modal stays until the user selects one of its buttons.

Use them only when the user needs to know. Good uses:

- Settings were saved, or could not be saved.
- A login worked, or failed.
- An action the user asked for is done.

## Show a toast

Call `pushToastMessage` with a type, a title and a message:

```js title="index.js"
this.commandRouter.pushToastMessage('success', this.strings.PLUGIN_NAME, this.strings.LOGIN_DONE);
```

The type sets the toast's colour and icon:

| Type | Use it for |
| --- | --- |
| `success` | An action that worked |
| `info` | Something the user should know, such as a login in progress |
| `warning` | A problem the plugin worked around |
| `error` | An action that failed |

Take the title and the message from the plugin's i18n files, so they appear in the user's language. The template loads them into `this.strings` in `onStart`.

## Show a modal

### 1. Declare the permission

In `volumio-plugin.json`, add `ui:modal` to `permissions`. Moderators read the permissions when they review the plugin.

```json title="volumio-plugin.json"
"permissions": ["ui:toast", "ui:modal"]
```

### 2. Open the modal

Send an `openModal` message with `broadcastMessage`. Every open Volumio web UI shows it:

```js title="index.js"
this.commandRouter.broadcastMessage('openModal', {
  title: this.strings.RESET_TITLE,
  message: this.strings.RESET_MESSAGE,
  size: 'lg',
  buttons: [
    { name: this.strings.CANCEL, class: 'btn btn-info' },
    {
      name: this.strings.RESET,
      class: 'btn btn-warning',
      emit: 'callMethod',
      payload: { endpoint: 'miscellanea/hello_volumio', method: 'resetSettings', data: {} },
    },
  ],
});
```

Any button closes the modal. A button without `emit` only closes it.

### 3. Handle the answer

A button with `emit: 'callMethod'` calls a method of a plugin. `endpoint` is the plugin's `<type>/<id>`, `method` the method's name, and `data` its argument. Add the method to `index.js`:

```js title="index.js"
resetSettings() {
  this.config.set('greeting', 'Hello from Volumio');
  this.commandRouter.pushToastMessage('success', this.strings.PLUGIN_NAME, this.strings.RESET_DONE);
  return libQ.resolve();
}
```

## Check that it works

1. Install the plugin with `npx --package=@volumio/plugin-sdk volumio-plugin deploy 192.168.1.20 .`.
2. Open the Volumio web UI and do what shows the toast or the modal.
3. For a modal, select the button with `emit: 'callMethod'`. The toast from `resetSettings` appears.

## Related

- [index.js methods](/plugins/reference/index-js#calls-into-volumio)
- [Add a settings page](/plugins/how-to/settings-page)
