A Symfony bundle for displaying toast notifications from flash messages, with no Bootstrap CSS or JavaScript dependency.
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
composer require asmitta-01/toast-bundle
The bundle is compatible with Symfony 6, 7 and 8.
If your application exposes bundle assets through the public directory, install them after requiring the package:
php bin/console assets:install
If your application doesn't use Symfony Flex, enable the bundle in config/bundles.php:
return [
// ...
Asmitta\ToastBundle\AsmittaToastBundle::class => ['all' => true],
];
Create a configuration file at config/packages/asmitta_toast.yaml, see docs/config.md.
use Asmitta\ToastBundle\Enum\ToastType;
public function someAction(Request $request): Response
{
$this->addFlash('success', 'Operation completed successfully!'); // 'success' or ToastType::SUCCESS->value
$this->addFlash('warning', 'Please check your input.');
$this->addFlash('error', 'Something went wrong.');
$this->addFlash('info', 'Here is some information.');
return $this->render('your_template.html.twig');
}
{{ render_toasts() }}
By default, the bundle automatically loads its CSS and JavaScript assets when rendering toasts.
If you use the with_icon or colored_icon templates, include Bootstrap Icons in your page:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
If you prefer to manage assets manually (for example with your own pipeline), disable auto loading:
asmitta_toast:
auto_load_assets: false
Then include the assets yourself:
<link href="{{ asset('bundles/asmittaToast/css/toast.css') }}" rel="stylesheet">
<link href="{{ asset('bundles/asmittaToast/css/spacing.css') }}" rel="stylesheet">
<link href="{{ asset('bundles/asmittaToast/css/toast-progress-bar.css') }}" rel="stylesheet"> <!-- optional -->
<script src="{{ asset('bundles/asmittaToast/js/toast.js') }}"></script>
The bundle supports these flash message types:
success → Green toastwarning → Yellow toasterror or danger → Red toastinfo (default) → Light Blue toasttoast to asmitta-toastasmitta- prefixed classesHow can I help you explore Laravel packages today?