Skip to content

SweetToast

Viames Marino edited this page Mar 31, 2026 · 1 revision

Pair framework: SweetToast

Pair\Html\SweetToast generates JavaScript code for SweetAlert2 toast notifications.

Constructor

new SweetToast(string $title, string $message, ?string $type = 'info')

Valid types: info, success, warning, error, question, progress.

Fluent methods

The API mirrors IziToast for easier driver switching:

  • balloon(bool $flag)
  • class(string $class)
  • close(bool $flag)
  • closeOnEscape(bool $flag)
  • displayMode(int $mode)
  • icon(string $icon)
  • id(string $id)
  • image(string $image)
  • position(string $position)
  • progressBar(bool $flag)
  • theme(string $theme)
  • timeout(int|bool $timeout)
  • overlay(bool $flag)
  • render(): string

Unsupported iziToast-only options are kept as compatibility no-ops when SweetAlert2 does not offer an equivalent behavior.

Application usage

Configure the driver once:

$app->setToastDriver('sweetalert');

Then the standard helpers automatically emit SweetAlert2 toasts:

$this->toast('Saved', 'User updated', 'success');
$this->toastError('Error', 'Unable to save user');

Notes

  • SweetToast requires SweetAlert2 to be available in the page.
  • Custom icon class names are rendered through SweetAlert2 iconHtml.
  • When no position is provided, SweetToast uses the native SweetAlert2 default position.
  • position() accepts both iziToast-style values (topRight) and SweetAlert2 aliases (top-end, bottom-start).

See also: SweetAlert, IziToast, PairUI.js, Application.

Clone this wiki locally