kaistaerk/ajax-flash-message-bundle

Handle ajax flash messages for symfony 5

Installs: 133

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

Type:symfony-bundle

2.1.1 2024-01-06 10:37 UTC

This package is auto-updated.

Last update: 2024-04-06 11:11:56 UTC


README

Symfony bundle to handle symfony flash messages called by ajax actions

Bundle will catch all FlashBag messages set in ajax actions in controllers when send an request via jquery and display it as it would show flash messages used in normal symfony controller actions. You can override flash message styles as you wish. At the moment they should look quite user friendly/UX.

Step 1: Install package

composer req kaistaerk/ajax-flash-message-bundle

Step 2: Install assets

php app/console assets:install public --symlink --relative

If your public directory is not public please modify the command above.

Step 3: Include the messages template

In layout file:

{{ include('@AjaxFlashMessage/Messenger/messages.html.twig') }}

Step 4: add assets to your main layout file

Add jQuery as well if it's not already done.

{% block javascripts %}
    // ...
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" type="text/javascript"></script>
    <script src="{{ asset('bundles/ajaxflashmessage/js/jquery.flash-messenger.js') }}" type="text/javascript"></script>
{% endblock %}
{% block stylesheets %}
    // ...
    <link href="{{ asset('bundles/ajaxflashmessage/css/flash-message.css') }}" type="text/css" rel="stylesheet" />
{% endblock %}

Usage

Add this call to a script block in your layout or to some of your templates:

<script>
$('#flash-messages').flashNotification('init');
</script>