Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-13T11:34:49.050Z
Answers.LastActivityDate: 2016-06-13T11:34:49.050Z
Answers.UserDisplayName: Mike Pepper
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-13T11:30:47.893Z
Answers.LastActivityDate: 2016-06-13T11:30:47.893Z
Answers.UserDisplayName: Steve Rowling
Body: <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>
  
Tags: <plugin-craftcommerce>
Title: Craft Commerce: Detecting & Styling Flash Messages?
ThreadText: # 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') %}
      <div data-alert class="alert-box info radius">
        {{ craft.session.getFlash('notice') }}
        <a href="#" class="close">&times;</a>
      </div>
  {% endif %}
  
  {% if craft.session.getFlash('error') %}
      <div data-alert class="alert-box alert radius">
        {{ craft.session.getFlash('error') }}
        <a href="#" class="close">&times;</a>
      </div>
  {% 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 %}
      <div data-alert class="alert-box info radius">
        {{ flashNotice }}
        <a href="#" class="close">&times;</a>
      </div>
  {% endif %}
  
  {% set flashError = craft.session.getFlash('error') %}
  {% if flashError %}
      <div data-alert class="alert-box alert radius">
        {{ flashError }}
        <a href="#" class="close">&times;</a>
      </div>
  {% endif %}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2016-06-13. Score: 6
  
  You can use [`hasFlash()`](https://craftcms.com/classreference/variables/UserSessionVariable#hasFlash-detail) 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) %}
      <div data-alert class="alert-box info radius">
        {{ craft.session.getFlash('notice') }}
        <a href="#" class="close">&times;</a>
      </div>
  {% endif %}
  
  ```
  
  or
  
  ```
  {% if craft.session.hasFlash('error') %}
      <div data-alert class="alert-box alert radius">
        {{ craft.session.getFlash('error') }}
        <a href="#" class="close">&times;</a>
      </div>
  {% endif %}
  
  ```
  
  This is because flash messages are generally designed to be accessed or displayed only once, on the subsequent request.
  
  
  ---
  
  