<p>You can use <a href="https://craftcms.com/classreference/variables/UserSessionVariable#hasFlash-detail"><code>hasFlash()</code></a> instead, or pass <code>false</code> as a third argument, otherwise the flash message is discarded after the first time it is accessed.</p>

<pre><code>{% if craft.session.getFlash('notice', null, false) %}
    &lt;div data-alert class="alert-box info radius"&gt;
      {{ craft.session.getFlash('notice') }}
      &lt;a href="#" class="close"&gt;&amp;times;&lt;/a&gt;
    &lt;/div&gt;
{% endif %}
</code></pre>

<p>or</p>

<pre><code>{% if craft.session.hasFlash('error') %}
    &lt;div data-alert class="alert-box alert radius"&gt;
      {{ craft.session.getFlash('error') }}
      &lt;a href="#" class="close"&gt;&amp;times;&lt;/a&gt;
    &lt;/div&gt;
{% endif %}
</code></pre>

<p>This is because flash messages are generally designed to be accessed or displayed only once, on the subsequent request.</p>

CC BY-SA 3.0
2016-06-13T11:34:49.050Z
2016-06-13T11:34:49.050Z
Mike Pepper
<p>Getting a flash message also deletes it, so you should set it to a variable first, otherwise, when you try to access it a second time, it will be empty.</p>

<p>So you need to do something like this:</p>

<pre><code>{% set flashNotice = craft.session.getFlash('notice') %}
{% if flashNotice %}
    &lt;div data-alert class="alert-box info radius"&gt;
      {{ flashNotice }}
      &lt;a href="#" class="close"&gt;&amp;times;&lt;/a&gt;
    &lt;/div&gt;
{% endif %}

{% set flashError = craft.session.getFlash('error') %}
{% if flashError %}
    &lt;div data-alert class="alert-box alert radius"&gt;
      {{ flashError }}
      &lt;a href="#" class="close"&gt;&amp;times;&lt;/a&gt;
    &lt;/div&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-06-13T11:30:47.893Z
2016-06-13T11:30:47.893Z
Steve Rowling
<p>I'm styling my flash messages in Craft Commerce - I added if statements to detect the type of flash message. I noticed however that the message no longer displays but the styling does get picked up. Any ideas what I might need to do here?</p>

<pre><code>{% if craft.session.getFlash('notice') %}
    &lt;div data-alert class="alert-box info radius"&gt;
      {{ craft.session.getFlash('notice') }}
      &lt;a href="#" class="close"&gt;&amp;times;&lt;/a&gt;
    &lt;/div&gt;
{% endif %}

{% if craft.session.getFlash('error') %}
    &lt;div data-alert class="alert-box alert radius"&gt;
      {{ craft.session.getFlash('error') }}
      &lt;a href="#" class="close"&gt;&amp;times;&lt;/a&gt;
    &lt;/div&gt;
{% endif %}
</code></pre>

<plugin-craftcommerce>
Craft Commerce: Detecting & Styling Flash Messages?
# Craft Commerce: Detecting & Styling Flash Messages?

(Asked by: username_0 on 2016-06-13)

I'm styling my flash messages in Craft Commerce - I added if statements to detect the type of flash message. I noticed however that the message no longer displays but the styling does get picked up. Any ideas what I might need to do here?
{% if craft.session.getFlash('notice') %}
    
      {{ craft.session.getFlash('notice') }}
      ×
    
{% endif %}

{% if craft.session.getFlash('error') %}
    
      {{ craft.session.getFlash('error') }}
      ×
    
{% endif %}

**Tags:** plugin-craftcommerce


---

## 2 answers

### Answer by username_2 on 2016-06-13. Score: 9 | Accepted answer

Getting a flash message also deletes it, so you should set it to a variable first, otherwise, when you try to access it a second time, it will be empty.
So you need to do something like this:
{% set flashNotice = craft.session.getFlash('notice') %}
{% if flashNotice %}
    
      {{ flashNotice }}
      ×
    
{% endif %}

{% set flashError = craft.session.getFlash('error') %}
{% if flashError %}
    
      {{ flashError }}
      ×
    
{% endif %}


---

### Answer by username_1 on 2016-06-13. Score: 6

You can use hasFlash() instead, or pass false as a third argument, otherwise the flash message is discarded after the first time it is accessed.
{% if craft.session.getFlash('notice', null, false) %}
    
      {{ craft.session.getFlash('notice') }}
      ×
    
{% endif %}

or
{% if craft.session.hasFlash('error') %}
    
      {{ craft.session.getFlash('error') }}
      ×
    
{% endif %}

This is because flash messages are generally designed to be accessed or displayed only once, on the subsequent request.


---

