pentiminax/ux-sweet-alert
SweetAlert2 integration for Symfony
4,382
25
| Install | |
|---|---|
composer require pentiminax/ux-sweet-alert |
|
| Latest Version: | v0.17.0 |
| PHP: | >=8.2 |
| License: | MIT |
| Last Updated: | Feb 18, 2026 |
| Links: | GitHub · Packagist |
Maintainer: Pentiminax
UX SweetAlert
UX SweetAlert is a Symfony bundle that integrates the SweetAlert2 library into your Symfony applications. It provides PHP helpers and a Stimulus controller to easily display alerts and toast notifications.
Requirements
- PHP 8.2 or higher
- Symfony StimulusBundle
- Composer
Installation
Install the library via Composer:
composer require pentiminax/ux-sweet-alert
Basic usage
To automatically display toasts and alerts in your templates, add the following Twig function in your base.html.twig (or the layout file):
{{ ux_sweet_alert_scripts() }}
Alerts
Inject the AlertManagerInterface and use the helper methods to create alerts:
use Pentiminax\UX\SweetAlert\AlertManagerInterface;
#[Route('/', name: 'app_homepage')]
public function index(AlertManagerInterface $alertManager): Response
{
$alertManager->success(
title: 'Update Successful',
text: 'Your settings have been saved.'
);
return $this->redirectToRoute('dashboard');
}
Toasts
Use the AlertManagerInterface service with the toast() method to create toast notifications:
use Pentiminax\UX\SweetAlert\AlertManagerInterface;
use Pentiminax\UX\SweetAlert\Enum\Position;
class HomeController extends AbstractController
{
#[Route('/', name: 'app_homepage')]
public function index(AlertManagerInterface $alertManager): Response
{
$alertManager->toast(
title: 'title',
text: 'text',
position: Position::TOP_END,
timer: 3000,
timerProgressBar: true
);
return $this->render('home/index.html.twig');
}
}