Automatically closing bootstrap alerts

Say you have the following in your template, in order to show flashMessages in your twig template:

{% for flashMessage in app.session.flashbag.get('alert-danger') %}
{{ flashMessage }}
{% endfor %}

And the following in your controller:

    'And error has occured!'

You can now add this simple piece of javascript to your template:

$(".alert").delay(4000).slideUp(200, function() {

Wich will automatically close any flashMessage rendered, after 4 seconds.

Like this article? Share it!