asmitta-01/toast-bundle
最新稳定版本:v0.3.0
Composer 安装命令:
composer require asmitta-01/toast-bundle
包简介
UX Toast display for your Symfony project.
关键字:
README 文档
README
A Symfony bundle for displaying Bootstrap toasts from flash messages.
Installation
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
Configuration
if your application dont'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, read docs.
Usage
1. Add flash messages in your controller
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'); }
2. Include Bootstrap CSS and JS in your template
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
If you're going to show the progress bar in your toasts, also include this css file:
<link href="{{ asset('bundles/asmittatoast/css/toast-progress-bar.css') }}" rel="stylesheet">
3. Add the toast function to your template
{{ render_toasts() }}
Toast Types
The bundle supports these flash message types:
success→ Green toastwarning→ Yellow toasterrorordanger→ Red toastinfo(default) → Light Blue toast
Features
- Automatic mapping of flash message types to Bootstrap toast variants
- Configurable auto-hide timer (default: 5 seconds)
- Flexible positioning (7 positions available, see ToastPosition Enum)
- Limit maximum toasts per type
- Optional progress bar showing remaining time
- Dismissible toasts with close button
- Responsive design
- Twig template-based rendering
- Full configuration support
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-07